|  | 
| 1 | 1 | run: | 
| 2 | 2 |   - exec: | 
| 3 |  | -     cmd: | 
| 4 |  | -       - "mkdir -p /shared/ssl/" | 
| 5 |  | -  - replace: | 
| 6 |  | -     filename: "/etc/nginx/conf.d/discourse.conf" | 
| 7 |  | -     from: /server.+{/ | 
| 8 |  | -     to: | | 
| 9 |  | -       server { | 
| 10 |  | -         listen 80; | 
| 11 |  | -         return 301 https://$$ENV_DISCOURSE_HOSTNAME$request_uri; | 
| 12 |  | -       } | 
| 13 |  | -       server { | 
| 14 |  | -  - replace: | 
| 15 |  | -     filename: "/etc/nginx/conf.d/discourse.conf" | 
| 16 |  | -     from: /listen 80;\s+gzip on;/m | 
| 17 |  | -     to: | | 
| 18 |  | -       listen 443 ssl; | 
| 19 |  | -       http2 on; | 
| 20 |  | -       SSL_TEMPLATE_SSL_BLOCK | 
| 21 |  | -  - replace: | 
| 22 |  | -     filename: "/etc/nginx/conf.d/discourse.conf" | 
| 23 |  | -     from: /listen 80;\s+listen \[::\]:80;\s+gzip on;/m | 
| 24 |  | -     to: | | 
| 25 |  | -       listen 443 ssl; | 
| 26 |  | -       listen [::]:443 ssl; | 
| 27 |  | -       http2 on; | 
| 28 |  | -       SSL_TEMPLATE_SSL_BLOCK | 
| 29 |  | -  - replace: | 
| 30 |  | -     hook: ssl | 
| 31 |  | -     filename: "/etc/nginx/conf.d/discourse.conf" | 
| 32 |  | -     from: /SSL_TEMPLATE_SSL_BLOCK/ | 
| 33 |  | -     to: | | 
| 34 |  | -
 | 
| 35 |  | -       ssl_protocols TLSv1.2 TLSv1.3; | 
| 36 |  | -       ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384; | 
| 37 |  | -       ssl_prefer_server_ciphers off; | 
| 38 |  | -
 | 
| 39 |  | -       ssl_certificate /shared/ssl/ssl.crt; | 
| 40 |  | -       ssl_certificate_key /shared/ssl/ssl.key; | 
| 41 |  | -
 | 
| 42 |  | -       ssl_session_tickets off; | 
| 43 |  | -       ssl_session_timeout 1d; | 
| 44 |  | -       ssl_session_cache shared:SSL:1m; | 
| 45 |  | -
 | 
| 46 |  | -       gzip on; | 
| 47 |  | -
 | 
| 48 |  | -       add_header Strict-Transport-Security 'max-age=31536000'; # remember the certificate for a year and automatically connect to HTTPS for this domain | 
| 49 |  | -
 | 
| 50 |  | -       if ($http_host != $$ENV_DISCOURSE_HOSTNAME) { | 
| 51 |  | -          rewrite (.*) https://$$ENV_DISCOURSE_HOSTNAME$1 permanent; | 
| 52 |  | -       } | 
| 53 |  | -  - replace: | 
| 54 |  | -     filename: "/etc/nginx/conf.d/discourse.conf" | 
| 55 |  | -     from: "location @discourse {" | 
| 56 |  | -     to: | | 
| 57 |  | -       location @discourse { | 
| 58 |  | -       add_header Strict-Transport-Security 'max-age=31536000'; # remember the certificate for a year and automatically connect to HTTPS for this domain | 
|  | 3 | +      cmd: | 
|  | 4 | +        - "mkdir -p /shared/ssl/" | 
|  | 5 | + | 
|  | 6 | +  - file: | 
|  | 7 | +      path: "/etc/nginx/conf.d/outlets/before-server/redirect-http-to-https.conf" | 
|  | 8 | +      contents: | | 
|  | 9 | +        server { | 
|  | 10 | +          listen 80; | 
|  | 11 | +          return 301 https://$$ENV_DISCOURSE_HOSTNAME$request_uri; | 
|  | 12 | +        } | 
|  | 13 | +
 | 
|  | 14 | +  - exec: rm /etc/nginx/conf.d/outlets/server/http.conf | 
|  | 15 | + | 
|  | 16 | +  - file: | 
|  | 17 | +      hook: ssl | 
|  | 18 | +      path: "/etc/nginx/conf.d/outlets/server/https.conf" | 
|  | 19 | +      contents: | | 
|  | 20 | +        listen 443 ssl; | 
|  | 21 | +        http2 on; | 
|  | 22 | +
 | 
|  | 23 | +        ssl_protocols TLSv1.2 TLSv1.3; | 
|  | 24 | +        ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384; | 
|  | 25 | +        ssl_prefer_server_ciphers off; | 
|  | 26 | +
 | 
|  | 27 | +        ssl_certificate /shared/ssl/ssl.crt; | 
|  | 28 | +        ssl_certificate_key /shared/ssl/ssl.key; | 
|  | 29 | +
 | 
|  | 30 | +        ssl_session_tickets off; | 
|  | 31 | +        ssl_session_timeout 1d; | 
|  | 32 | +        ssl_session_cache shared:SSL:1m; | 
|  | 33 | +
 | 
|  | 34 | +        add_header Strict-Transport-Security 'max-age=31536000'; | 
|  | 35 | +
 | 
|  | 36 | +        if ($http_host != $$ENV_DISCOURSE_HOSTNAME) { | 
|  | 37 | +           rewrite (.*) https://$$ENV_DISCOURSE_HOSTNAME$1 permanent; | 
|  | 38 | +        } | 
|  | 39 | +
 | 
|  | 40 | +  - file: | 
|  | 41 | +      path: "/etc/nginx/conf.d/outlets/discourse/https.conf" | 
|  | 42 | +      contents: | | 
|  | 43 | +        add_header Strict-Transport-Security 'max-age=31536000'; | 
|  | 44 | +
 | 
|  | 45 | +  - exec: | 
|  | 46 | +      cmd: | 
|  | 47 | +        - |- | 
|  | 48 | +          if [ -f "/proc/net/if_inet6" ] ; then | 
|  | 49 | +            sed -i 's/listen 80;/listen 80;\nlisten [::]:80;/g' /etc/nginx/conf.d/outlets/before-server/redirect-http-to-https.conf | 
|  | 50 | +            sed -i 's/listen 443 ssl;/listen 443 ssl;\nlisten [::]:443 ssl;/g' /etc/nginx/conf.d/outlets/server/https.conf | 
|  | 51 | +          fi | 
0 commit comments