Skip to content

Commit

Permalink
🎉 Awesome Nginx Certbot Compose! with some improvements
Browse files Browse the repository at this point in the history
- domain names are figured out from /etc/nginx/conf.d/*.conf filenames;
- top-level directories in repo represent Compose services (for
  autocomplete);
- static websites will be contained in a mounted directory
  /var/www/websites.
  • Loading branch information
luke10x committed Mar 21, 2023
1 parent 62a1c61 commit dd75521
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/data/certbot
certbot/
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
MIT License

Copyright (c) 2018 Philipp Schmieder
Copyright (c) 2023 Luke 10X

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
31 changes: 0 additions & 31 deletions data/nginx/app.conf

This file was deleted.

11 changes: 6 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ services:
image: nginx:1.15-alpine
restart: unless-stopped
volumes:
- ./data/nginx:/etc/nginx/conf.d
- ./data/certbot/conf:/etc/letsencrypt
- ./data/certbot/www:/var/www/certbot
- ./nginx/conf.d:/etc/nginx/conf.d:ro
- ./nginx/www:/var/www/sites:ro
- ./certbot/letsencrypt:/etc/letsencrypt:ro
- ./certbot/www:/var/www/certbot:ro
ports:
- "80:80"
- "443:443"
Expand All @@ -16,6 +17,6 @@ services:
image: certbot/certbot
restart: unless-stopped
volumes:
- ./data/certbot/conf:/etc/letsencrypt
- ./data/certbot/www:/var/www/certbot
- ./certbot/letsencrypt:/etc/letsencrypt:rw
- ./certbot/www:/var/www/certbot:rw
entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'"
23 changes: 16 additions & 7 deletions init-letsencrypt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,18 @@ if ! [ -x "$(command -v docker-compose)" ]; then
exit 1
fi

domains=(example.org www.example.org)
function lsconf() {
for file in ./nginx/conf.d/*.conf; do
filename=$(basename "$file")
echo "${filename%.*}"
done
}

configs=$(lsconf | xargs)
domains=($configs)

rsa_key_size=4096
data_path="./data/certbot"
data_path="./certbot/letsencrypt"
email="" # Adding a valid address is strongly recommended
staging=0 # Set to 1 if you're testing your setup to avoid hitting request limits

Expand All @@ -19,17 +28,17 @@ if [ -d "$data_path" ]; then
fi


if [ ! -e "$data_path/conf/options-ssl-nginx.conf" ] || [ ! -e "$data_path/conf/ssl-dhparams.pem" ]; then
if [ ! -e "$data_path/options-ssl-nginx.conf" ] || [ ! -e "$data_path/ssl-dhparams.pem" ]; then
echo "### Downloading recommended TLS parameters ..."
mkdir -p "$data_path/conf"
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"
curl -s https://raw.githubusercontent.com/certbot/certbot/master/certbot/certbot/ssl-dhparams.pem > "$data_path/conf/ssl-dhparams.pem"
mkdir -p "$data_path"
curl -s https://raw.githubusercontent.com/certbot/certbot/master/certbot-nginx/certbot_nginx/_internal/tls_configs/options-ssl-nginx.conf > "$data_path/options-ssl-nginx.conf"
curl -s https://raw.githubusercontent.com/certbot/certbot/master/certbot/certbot/ssl-dhparams.pem > "$data_path/ssl-dhparams.pem"
echo
fi

echo "### Creating dummy certificate for $domains ..."
path="/etc/letsencrypt/live/$domains"
mkdir -p "$data_path/conf/live/$domains"
mkdir -p "$data_path/live/$domains"
docker-compose run --rm --entrypoint "\
openssl req -x509 -nodes -newkey rsa:$rsa_key_size -days 1\
-keyout '$path/privkey.pem' \
Expand Down
2 changes: 2 additions & 0 deletions nginx/conf.d/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
2 changes: 2 additions & 0 deletions nginx/www/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore

0 comments on commit dd75521

Please sign in to comment.