Sample repository that contains a minimal project with Nginx and Certbot running under Docker containers that request Let's Encrypt certificate for your domains.
Run this command to automatic setup the project:
FILE='./setup.sh'; curl -fsSLo "$FILE" 'https://raw.githubusercontent.com/rhuanpk/ncd/main/setup.sh' && chmod +x "$FILE" && "$FILE"
In all cases:
- Keep open ports
80
and443
in your firewall.
Before run the script:
- Creates the VPS (or use local exposed IP);
- Creates the A/AAAA domain that points to IP server.
After run the script:
- Change the config files (docker compose and nginx) as necessary;
- After all done if desired can exlude
.git
folder; - Add crontab for regular renewal attempt e.g.:
0 0 15 * * docker-compose -f /path/to/docker-compose.yml up -d certbot
30 0 15 * * docker-compose -f /path/to/docker-compose.yml restart nginx
Running by the recommended command, the script will execute in order:
-
Clone this repository (
git
); -
Comment the first command (
sed
); -
Enter the repository folder (
cd
); -
Iterate over modified or untracked files if it exists (
for
):-
Case untrackeds:
- Ask to clean them (
read
,for
,su || sudo
,git
).
OBS: This is necessary in case the user runs the setup script again (with./setup.sh
) to generate the certificates, opting for a different strategy so this flow deletes the created certificates. Case you desire only update the certificates, choose "n".
- Ask to clean them (
-
Case modifieds:
- Ask to restore them (
read
,for
,git
).
- Ask to restore them (
-
-
Ask for environment type (
read
):-
Case production:
- Ask for production domains (
read
);
- Ask for production domains (
-
Case testing:
- Set default local testing domains (
su > echo || sudo > tee
); OR - Ask for testing domains (
read
).
- Set default local testing domains (
-
-
Ask for certificate generation strategy (
read
):-
Case single:
- Setup Nginx config with all domains and generate one certificate for all too (
heredoc
).
- Setup Nginx config with all domains and generate one certificate for all too (
-
Case multiple:
- Iterate over all domains grouping them with max amount of 2 consisting in the
domain.*
and yourwww.domain.*
(for
); - Iterate over all group of domains appending a specific confi in Nginx cofig file (
for
,heredoc
).
- Iterate over all domains grouping them with max amount of 2 consisting in the
-
-
Edit config files based on options chosen (
sed
); -
Copy pre Nginx config for ACME challange (
cp
); -
Enter the
project/
folder (cd
); -
Execute ssl script (
./ssl.sh
); -
Ask for email of the admin (
read
); -
Create some necessary folders (
mkdir
); -
Start Nginx container (
docker
); -
Request Let's Encrypt certificates (
docker > certbot
); -
Download recommended files for Nginx (
curl
); -
Copy final Nginx config (with HTTPS redirect) (
cp
); -
Reload Nginx daemon (
docker
).