Skip to content

Commit dd75521

Browse files
committed
🎉 Awesome Nginx Certbot Compose! with some improvements
- 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.
1 parent 62a1c61 commit dd75521

File tree

7 files changed

+28
-44
lines changed

7 files changed

+28
-44
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
/data/certbot
1+
certbot/

LICENSE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
MIT License
22

33
Copyright (c) 2018 Philipp Schmieder
4+
Copyright (c) 2023 Luke 10X
45

56
Permission is hereby granted, free of charge, to any person obtaining a copy
67
of this software and associated documentation files (the "Software"), to deal

data/nginx/app.conf

Lines changed: 0 additions & 31 deletions
This file was deleted.

docker-compose.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ services:
55
image: nginx:1.15-alpine
66
restart: unless-stopped
77
volumes:
8-
- ./data/nginx:/etc/nginx/conf.d
9-
- ./data/certbot/conf:/etc/letsencrypt
10-
- ./data/certbot/www:/var/www/certbot
8+
- ./nginx/conf.d:/etc/nginx/conf.d:ro
9+
- ./nginx/www:/var/www/sites:ro
10+
- ./certbot/letsencrypt:/etc/letsencrypt:ro
11+
- ./certbot/www:/var/www/certbot:ro
1112
ports:
1213
- "80:80"
1314
- "443:443"
@@ -16,6 +17,6 @@ services:
1617
image: certbot/certbot
1718
restart: unless-stopped
1819
volumes:
19-
- ./data/certbot/conf:/etc/letsencrypt
20-
- ./data/certbot/www:/var/www/certbot
20+
- ./certbot/letsencrypt:/etc/letsencrypt:rw
21+
- ./certbot/www:/var/www/certbot:rw
2122
entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'"

init-letsencrypt.sh

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,18 @@ if ! [ -x "$(command -v docker-compose)" ]; then
55
exit 1
66
fi
77

8-
domains=(example.org www.example.org)
8+
function lsconf() {
9+
for file in ./nginx/conf.d/*.conf; do
10+
filename=$(basename "$file")
11+
echo "${filename%.*}"
12+
done
13+
}
14+
15+
configs=$(lsconf | xargs)
16+
domains=($configs)
17+
918
rsa_key_size=4096
10-
data_path="./data/certbot"
19+
data_path="./certbot/letsencrypt"
1120
email="" # Adding a valid address is strongly recommended
1221
staging=0 # Set to 1 if you're testing your setup to avoid hitting request limits
1322

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

2130

22-
if [ ! -e "$data_path/conf/options-ssl-nginx.conf" ] || [ ! -e "$data_path/conf/ssl-dhparams.pem" ]; then
31+
if [ ! -e "$data_path/options-ssl-nginx.conf" ] || [ ! -e "$data_path/ssl-dhparams.pem" ]; then
2332
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"
33+
mkdir -p "$data_path"
34+
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"
35+
curl -s https://raw.githubusercontent.com/certbot/certbot/master/certbot/certbot/ssl-dhparams.pem > "$data_path/ssl-dhparams.pem"
2736
echo
2837
fi
2938

3039
echo "### Creating dummy certificate for $domains ..."
3140
path="/etc/letsencrypt/live/$domains"
32-
mkdir -p "$data_path/conf/live/$domains"
41+
mkdir -p "$data_path/live/$domains"
3342
docker-compose run --rm --entrypoint "\
3443
openssl req -x509 -nodes -newkey rsa:$rsa_key_size -days 1\
3544
-keyout '$path/privkey.pem' \

nginx/conf.d/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore

nginx/www/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore

0 commit comments

Comments
 (0)