2024-07-31 13:21:56 +08:00
|
|
|
# Launching new servers with SSL certificates
|
|
|
|
|
|
|
|
## Short description
|
|
|
|
|
2024-09-10 15:02:52 +08:00
|
|
|
docker compose certbot configurations with Backward compatibility (without certbot container).
|
|
|
|
Use `docker compose --profile certbot up` to use this features.
|
2024-07-31 13:21:56 +08:00
|
|
|
|
|
|
|
## The simplest way for launching new servers with SSL certificates
|
|
|
|
|
|
|
|
1. Get letsencrypt certs
|
|
|
|
set `.env` values
|
|
|
|
```properties
|
|
|
|
NGINX_SSL_CERT_FILENAME=fullchain.pem
|
|
|
|
NGINX_SSL_CERT_KEY_FILENAME=privkey.pem
|
|
|
|
NGINX_ENABLE_CERTBOT_CHALLENGE=true
|
|
|
|
CERTBOT_DOMAIN=your_domain.com
|
|
|
|
CERTBOT_EMAIL=example@your_domain.com
|
|
|
|
```
|
2024-08-22 13:36:15 +08:00
|
|
|
execute command:
|
2024-07-31 13:21:56 +08:00
|
|
|
```shell
|
2024-09-10 15:02:52 +08:00
|
|
|
docker network prune
|
|
|
|
docker compose --profile certbot up --force-recreate -d
|
2024-07-31 13:21:56 +08:00
|
|
|
```
|
|
|
|
then after the containers launched:
|
|
|
|
```shell
|
2024-09-10 15:02:52 +08:00
|
|
|
docker compose exec -it certbot /bin/sh /update-cert.sh
|
2024-07-31 13:21:56 +08:00
|
|
|
```
|
2024-09-10 15:02:52 +08:00
|
|
|
2. Edit `.env` file and `docker compose --profile certbot up` again.
|
2024-07-31 13:21:56 +08:00
|
|
|
set `.env` value additionally
|
|
|
|
```properties
|
|
|
|
NGINX_HTTPS_ENABLED=true
|
|
|
|
```
|
2024-08-22 13:36:15 +08:00
|
|
|
execute command:
|
2024-07-31 13:21:56 +08:00
|
|
|
```shell
|
2024-09-10 15:02:52 +08:00
|
|
|
docker compose --profile certbot up -d --no-deps --force-recreate nginx
|
2024-07-31 13:21:56 +08:00
|
|
|
```
|
|
|
|
Then you can access your serve with HTTPS.
|
|
|
|
[https://your_domain.com](https://your_domain.com)
|
|
|
|
|
|
|
|
## SSL certificates renewal
|
|
|
|
|
|
|
|
For SSL certificates renewal, execute commands below:
|
|
|
|
|
|
|
|
```shell
|
2024-09-10 15:02:52 +08:00
|
|
|
docker compose exec -it certbot /bin/sh /update-cert.sh
|
|
|
|
docker compose exec nginx nginx -s reload
|
2024-07-31 13:21:56 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
## Options for certbot
|
|
|
|
|
|
|
|
`CERTBOT_OPTIONS` key might be helpful for testing. i.e.,
|
|
|
|
|
|
|
|
```properties
|
|
|
|
CERTBOT_OPTIONS=--dry-run
|
|
|
|
```
|
|
|
|
|
|
|
|
To apply changes to `CERTBOT_OPTIONS`, regenerate the certbot container before updating the certificates.
|
|
|
|
|
|
|
|
```shell
|
2024-09-10 15:02:52 +08:00
|
|
|
docker compose --profile certbot up -d --no-deps --force-recreate certbot
|
|
|
|
docker compose exec -it certbot /bin/sh /update-cert.sh
|
2024-07-31 13:21:56 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
Then, reload the nginx container if necessary.
|
|
|
|
|
|
|
|
```shell
|
2024-09-10 15:02:52 +08:00
|
|
|
docker compose exec nginx nginx -s reload
|
2024-07-31 13:21:56 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
## For legacy servers
|
|
|
|
|
|
|
|
To use cert files dir `nginx/ssl` as before, simply launch containers WITHOUT `--profile certbot` option.
|
|
|
|
|
|
|
|
```shell
|
2024-09-10 15:02:52 +08:00
|
|
|
docker compose up -d
|
2024-08-22 13:36:15 +08:00
|
|
|
```
|