docker 里面let's encrypt+Nginx

先用docker建let's encrypt

sudo docker run --rm -p 80:80 -p 443:443 -v /etc/letsencrypt:/etc/letsencrypt quay.io/letsencrypt/letsencrypt auth --standalone -m email@domain --agree-tos -d example.com

此时已经生成let's encrypt 的证书

然后调用Nginx

sudo docker run --name nginx -v /etc/letsencrypt:/etc/letsencrypt -d -p 80:80 -p 443:443 -d nginx

搞定后进入contianer里面

sudo docker exec -it container_number /bin/bash

修改Ngnix的配置文件(在 /etc/nginx/conf.d 里面)的default.conf

在listen 80; 下面加这几行

 

listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

搞定后退出容器重启容器

sudo docker restart container_number

然后还要将自己的网站放在 /usr/share/nginx/html/ 下面

sudo docker cp example.html  container_number:/usr/share/nginx/html/example.html

然后就搞定

posted on 2020-06-06 15:55  redmondfans  阅读(482)  评论(0编辑  收藏  举报