我在 EC2 实例上运行 dockerized django。我在 docker 容器中配置了 nginx,并在 docker 容器中获得了证书。(我遵循了以下指南:https://www.humankode.com/ssl/how-to-set-up-free-ssl-certificates-from-lets-encrypt-using-docker-and-nginx)
问题是我偏离了教程,当我有证书时,我将它们复制到服务器/etc/letsencrypt/live/mydomain.com$
。我使用以下命令创建了我的证书:
sudo docker run -it --rm -v /docker-volumes/etc/letsencrypt:/etc/letsencrypt -v /docker-volumes/var/lib/letsencrypt:/var/lib/letsencrypt -v /docker/letsencrypt-docker-nginx/src/letsencrypt/letsencrypt-site:/data/letsencrypt -v "/docker-volumes/var/log/letsencrypt:/var/log/letsencrypt" \
certbot/certbot certonly --webroot --email [email protected] --agree-tos --no-eff-email --webroot-path=/data/letsencrypt -d mydomain
现在我想设置自动续订但我认为我的结构很乱。
当我尝试certbot certonly --standalone --staging -d mydomain
我明白了live directory exists for mydomain
,但什么都没有更新。
当我尝试时,sudo certbot certonly --nginx --staging -d mydomain
我得到了nginx: [error] invalid PID number
。
我不太清楚接下来该做什么。另外,我不知道我的 nginx 在服务器上的 docker 容器中运行,并且我为我的服务器请求证书,这是否有问题。
非常感谢任何帮助或建议。提前致谢!
我的 nginx 配置和我的 docker 组成:
production-nginx-container:
container_name: 'production-nginx-container'
image: nginx:latest
ports:
- "80:80"
- "443:443"
volumes: ##The following files are found on AWS EC2 instance.
- /etc/nginx-conf/myconf.conf:/etc/nginx/conf.d/default.conf
- /etc/letsencrypt/live/mydomain/fullchain.pem:/etc/letsencrypt/live/mydomain/fullchain.pem
- /etc/letsencrypt/live/mydomain/privkey.pem:/etc/letsencrypt/live/mydomain/privkey.pem
depends_on:
- django
server {
listen 443 ssl;
server_name mydomain.de;
charset utf-8;
ssl_stapling off;
ssl_stapling_verify off;
ssl_certificate /etc/letsencrypt/live/heatbe.at/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mydomain.de/privkey.pem;
set $my_host $http_host;
if ($http_host = "mydomain.de") {
set $my_host "mydomain.de";
}
location / {
proxy_pass http://django:5000;
proxy_set_header Host $my_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
server {
listen 80 ;
server_name mydomain.de;
return 301 https://mydomain.de$request_uri;
}
server {
listen 80 ;
server_name www.mydomain.de;
return 301 https://mydomain.de$request_uri;
}
server {
listen 443 ;
server_name www.mydomain.de;
return 301 https://mydomain.de$request_uri;
ssl_stapling off;
ssl_stapling_verify off;
ssl_certificate /etc/letsencrypt/live/mydomain.de/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mydomain.de/privkey.pem;
}