Преглед изворни кода

Updates for supporting certbot (#2)

master
Jesus Federico пре 4 година
родитељ
комит
a3830e3cc6
No account linked to committer's email address
3 измењених фајлова са 103 додато и 2 уклоњено
  1. 10
    2
      docker-compose.yml
  2. 80
    0
      init-letsencrypt.sh
  3. 13
    0
      nginx/sites.template

+ 10
- 2
docker-compose.yml Прегледај датотеку

@@ -14,7 +14,8 @@ services:
14 14
       - ./nginx/sites.template:/etc/nginx/sites-available/sites.template
15 15
       - ./nginx/default/html:/var/www/html
16 16
       - ./nginx/log/nginx:/var/log/nginx
17
-      - ./nginx/letsencrypt/:/etc/letsencrypt
17
+      - ./data/certbot/conf:/etc/letsencrypt
18
+      - ./data/certbot/www:/var/www/certbot
18 19
     ports:
19 20
       - "80:80"
20 21
       - "443:443"
@@ -22,7 +23,14 @@ services:
22 23
       - NGINX_HOSTNAME=${HOST_NAME:-sl}.${DOMAIN_SUB:-lab}.${DOMAIN_ROOT:-bigbluebutton.org}
23 24
     depends_on:
24 25
       - scalelite.api
25
-    command: /bin/bash -c "envsubst '$$NGINX_HOSTNAME' < /etc/nginx/sites-available/sites.template > /etc/nginx/sites-enabled/sites.conf && exec nginx -g 'daemon off;'"
26
+    command: /bin/bash -c "envsubst '$$NGINX_HOSTNAME' < /etc/nginx/sites-available/sites.template > /etc/nginx/sites-enabled/sites.conf && while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g 'daemon off;'"
27
+
28
+  certbot:
29
+    image: certbot/certbot
30
+    volumes:
31
+      - ./data/certbot/conf:/etc/letsencrypt
32
+      - ./data/certbot/www:/var/www/certbot
33
+    entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'"
26 34
 
27 35
   redis:
28 36
     image: redis

+ 80
- 0
init-letsencrypt.sh Прегледај датотеку

@@ -0,0 +1,80 @@
1
+#!/bin/bash
2
+
3
+if ! [ -x "$(command -v docker-compose)" ]; then
4
+  echo 'Error: docker-compose is not installed.' >&2
5
+  exit 1
6
+fi
7
+
8
+domains=(example.org www.example.org)
9
+rsa_key_size=4096
10
+data_path="./data/certbot"
11
+email="" # Adding a valid address is strongly recommended
12
+staging=0 # Set to 1 if you're testing your setup to avoid hitting request limits
13
+
14
+if [ -d "$data_path" ]; then
15
+  read -p "Existing data found for $domains. Continue and replace existing certificate? (y/N) " decision
16
+  if [ "$decision" != "Y" ] && [ "$decision" != "y" ]; then
17
+    exit
18
+  fi
19
+fi
20
+
21
+
22
+if [ ! -e "$data_path/conf/options-ssl-nginx.conf" ] || [ ! -e "$data_path/conf/ssl-dhparams.pem" ]; then
23
+  echo "### Downloading recommended TLS parameters ..."
24
+  mkdir -p "$data_path/conf"
25
+  curl -s https://raw.githubusercontent.com/certbot/certbot/master/certbot-nginx/certbot_nginx/_internal/tls_configs/options-ssl-nginx.conf > "$data_path/conf/options-ssl-nginx.conf"
26
+  curl -s https://raw.githubusercontent.com/certbot/certbot/master/certbot/certbot/ssl-dhparams.pem > "$data_path/conf/ssl-dhparams.pem"
27
+  echo
28
+fi
29
+
30
+echo "### Creating dummy certificate for $domains ..."
31
+path="/etc/letsencrypt/live/$domains"
32
+mkdir -p "$data_path/conf/live/$domains"
33
+docker-compose run --rm --entrypoint "\
34
+  openssl req -x509 -nodes -newkey rsa:1024 -days 1\
35
+    -keyout '$path/privkey.pem' \
36
+    -out '$path/fullchain.pem' \
37
+    -subj '/CN=localhost'" certbot
38
+echo
39
+
40
+
41
+echo "### Starting nginx ..."
42
+docker-compose up --force-recreate -d nginx
43
+echo
44
+
45
+echo "### Deleting dummy certificate for $domains ..."
46
+docker-compose run --rm --entrypoint "\
47
+  rm -Rf /etc/letsencrypt/live/$domains && \
48
+  rm -Rf /etc/letsencrypt/archive/$domains && \
49
+  rm -Rf /etc/letsencrypt/renewal/$domains.conf" certbot
50
+echo
51
+
52
+
53
+echo "### Requesting Let's Encrypt certificate for $domains ..."
54
+#Join $domains to -d args
55
+domain_args=""
56
+for domain in "${domains[@]}"; do
57
+  domain_args="$domain_args -d $domain"
58
+done
59
+
60
+# Select appropriate email arg
61
+case "$email" in
62
+  "") email_arg="--register-unsafely-without-email" ;;
63
+  *) email_arg="--email $email" ;;
64
+esac
65
+
66
+# Enable staging mode if needed
67
+if [ $staging != "0" ]; then staging_arg="--staging"; fi
68
+
69
+docker-compose run --rm --entrypoint "\
70
+  certbot certonly --webroot -w /var/www/certbot \
71
+    $staging_arg \
72
+    $email_arg \
73
+    $domain_args \
74
+    --rsa-key-size $rsa_key_size \
75
+    --agree-tos \
76
+    --force-renewal" certbot
77
+echo
78
+
79
+echo "### Reloading nginx ..."
80
+docker-compose exec nginx nginx -s reload

+ 13
- 0
nginx/sites.template Прегледај датотеку

@@ -9,6 +9,19 @@ server {
9 9
 
10 10
     listen 80;
11 11
     listen [::]:80;
12
+
13
+    location /.well-known/acme-challenge/ {
14
+        root /var/www/certbot;
15
+    }
16
+
17
+    location / {
18
+        return 301 https://$host$request_uri;
19
+    }
20
+}
21
+
22
+server {
23
+    server_name $NGINX_HOSTNAME;
24
+
12 25
     listen 443 ssl;
13 26
     listen [::]:443;
14 27
 

Loading…
Откажи
Сачувај