-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
41 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,7 @@ | |
#!/bin/bash | ||
|
||
yum update -y | ||
if ! rpm -q nginx certbot python3-certbot-nginx > /dev/null; then | ||
yum install -y nginx certbot python3-certbot-nginx | ||
fi | ||
yum install -y nginx certbot python3-certbot-nginx | ||
|
||
# Create nginx config | ||
sudo tee /etc/nginx/nginx.conf <<EOF | ||
|
@@ -14,7 +12,7 @@ events { | |
|
||
http { | ||
map $\http_host $\upstream { | ||
map $http_host $upstream { | ||
hostnames; | ||
%{ for domain, backend in services_map ~} | ||
${domain} ${backend}; | ||
|
@@ -25,7 +23,7 @@ http { | |
server { | ||
listen 80; | ||
server_name _; | ||
return 301 https://$\host$\request_uri; | ||
return 301 https://$host$request_uri; | ||
} | ||
server { | ||
|
@@ -43,22 +41,18 @@ http { | |
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; | ||
location / { | ||
proxy_pass http://$\upstream; | ||
proxy_set_header Host $\host; | ||
proxy_set_header X-Real-IP $\remote_addr; | ||
proxy_set_header X-Forwarded-For $\proxy_add_x_forwarded_for; | ||
proxy_set_header X-Forwarded-Proto $\scheme; | ||
proxy_pass http://$upstream; | ||
proxy_set_header Host $host; | ||
proxy_set_header X-Real-IP $remote_addr; | ||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
proxy_set_header X-Forwarded-Proto $scheme; | ||
} | ||
} | ||
} | ||
EOF | ||
|
||
# Obtain SSL certificate | ||
if ! certbot certificates | grep -q "${certbot_domains}"; then | ||
certbot --nginx -d ${certbot_domains} --non-interactive --agree-tos -m [email protected] | ||
else | ||
certbot renew --nginx --non-interactive | ||
fi | ||
certbot --nginx -d ${certbot_domains} --non-interactive --agree-tos -m [email protected] | ||
|
||
# Ensure Certbot auto-renewal is enabled | ||
systemctl enable certbot.timer | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#cloud-config | ||
cloud_final_modules: | ||
- [scripts-user, always] | ||
|
||
write_files: | ||
- path: /var/lib/cloud/scripts/per-boot/user-script.sh | ||
permissions: '0755' | ||
content: | | ||
${indent(8, nginx_config)} | ||
|
||
runcmd: | ||
- /var/lib/cloud/scripts/per-boot/user-script.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,21 @@ | ||
Content-Type: multipart/mixed; boundary="//" | ||
MIME-Version: 1.0 | ||
|
||
--// | ||
Content-Type: text/cloud-config; charset="us-ascii" | ||
MIME-Version: 1.0 | ||
Content-Transfer-Encoding: 7bit | ||
Content-Disposition: attachment; filename="cloud-config.txt" | ||
|
||
#cloud-config | ||
cloud_final_modules: | ||
- [scripts-user, always] | ||
- [scripts-user, always] | ||
|
||
write_files: | ||
- path: /var/lib/cloud/scripts/per-boot/user-script.sh | ||
permissions: '0755' | ||
content: | | ||
${indent(8, nginx_config)} | ||
--// | ||
Content-Type: text/x-shellscript; charset="us-ascii" | ||
MIME-Version: 1.0 | ||
Content-Transfer-Encoding: 7bit | ||
Content-Disposition: attachment; filename="userdata.txt" | ||
|
||
runcmd: | ||
- /var/lib/cloud/scripts/per-boot/user-script.sh | ||
${nginx_config} | ||
--// |