-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-ssl.sh
More file actions
executable file
·67 lines (56 loc) · 1.95 KB
/
setup-ssl.sh
File metadata and controls
executable file
·67 lines (56 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
# Simple Let's Encrypt setup for sokosam.com
DOMAIN="${1:-sokosam.com}"
EMAIL="${2:-}"
echo "### Setting up SSL for $DOMAIN"
# Create directories
sudo mkdir -p nginx/certbot/conf
sudo mkdir -p nginx/certbot/www
# Download recommended TLS parameters
echo "### Downloading TLS parameters..."
sudo curl -s https://raw.githubusercontent.com/certbot/certbot/master/certbot-nginx/certbot_nginx/_internal/tls_configs/options-ssl-nginx.conf -o nginx/certbot/conf/options-ssl-nginx.conf
sudo curl -s https://raw.githubusercontent.com/certbot/certbot/master/certbot/certbot/ssl-dhparams.pem -o nginx/certbot/conf/ssl-dhparams.pem
# Set proper permissions
sudo chmod -R 755 nginx/certbot
echo "### Requesting certificate from Let's Encrypt..."
# Build email argument
EMAIL_ARG=""
if [ -n "$EMAIL" ]; then
EMAIL_ARG="--email $EMAIL"
else
EMAIL_ARG="--register-unsafely-without-email"
fi
# Stop certbot container if running
docker compose -f docker-compose-prod.yml stop certbot 2>/dev/null
# Request certificate
sudo docker run --rm \
-v "$(pwd)/nginx/certbot/conf:/etc/letsencrypt" \
-v "$(pwd)/nginx/certbot/www:/var/www/certbot" \
certbot/certbot certonly \
--webroot \
--webroot-path /var/www/certbot \
$EMAIL_ARG \
-d $DOMAIN \
-d www.$DOMAIN \
--rsa-key-size 4096 \
--agree-tos \
--force-renewal \
--non-interactive
if [ $? -eq 0 ]; then
echo ""
echo "### Success! Certificate obtained."
echo "### Restarting containers..."
docker compose -f docker-compose-prod.yml restart certbot
docker compose -f docker-compose-prod.yml restart nginx
echo ""
echo "### Your site should now be accessible at:"
echo " https://$DOMAIN"
echo ""
else
echo "### Certificate request failed!"
echo "### Make sure:"
echo " 1. DNS for $DOMAIN and www.$DOMAIN points to this server"
echo " 2. Ports 80 and 443 are open"
echo " 3. No firewall is blocking the connection"
exit 1
fi