本文将介绍两种好用的自动化生成SSL证书的方式(certbot、acme)
一、certbot
步骤1:先做好域名dns解析到服务器ip上
步骤2:nginx必须添加的配置
server {
listen 80;
server_name xxxxx;#此处改为自己的域名
#配置http验证可访问
location /.well-known/acme-challenge/ {
#此目录都是nginx容器内的目录,对应宿主机volumes中的http验证目录,而宿主机的又与certbot容器中命令--webroot-path指定目录一致,从而就整个串起来了,解决了http验证问题
root /etc/nginx/cert/certbot/www/;
}
}
步骤3:启动nginx以及certbot,docker-compose.yml代码如下:
version: '3'
services:
nginx:
image: nginx:latest
container_name: nginx
restart: always
ports:
- "80:80"
- "443:443"
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
- ./nginx/cert:/etc/nginx/cert
- ./nginx/conf.d:/etc/nginx/conf.d
- ./nginx/log