centos 7 nginx 1.10.2
yum install -y epel-release yum install -y certbot
方法1:在网站根目录下建立一个.well-known的目录 方法2: mkdir -p /usr/local/nginx/cert/.well-known ln -s /usr/local/nginx/cert/.well-known /data/www/example.com/.well-known ln -s /usr/local/nginx/cert/.well-known /data/www/test.example.com/.well-known
certbot certonly --webroot -w /usr/local/nginx/cert -d example.com -d test.example.com 根据提示进行操做,通常能够正常生产证书文件。 证书文件的目录存放在: '/etc/letsencrypt/live/example.com/' 会有4个文件: cert.pem chain.pem fullchain.pem privkey.pem 特别要注意,这条命令只会将生成的证书放在这个目录,不会有一个/etc/letsencrypt/live/test.example.com/目录,test.example.com的证书和example.com的证书放在一块儿了,具体看后面的nginx配置。
server { listen 443 ssl http2; server_name example.com; index index.html index.htm index.php; root /data/www/example.com; ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH"; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; ssl_session_cache shared:SSL:10m; access_log off; } server { listen 443 ssl http2; server_name test.example.com; index index.html index.htm index.php; root /data/www/test.example.com; ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH"; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; ssl_session_cache shared:SSL:10m; access_log off; }
crontab -e # 新增以下定时任务 10 6 * * * /bin/certbot renew --quiet &>/dev/null Let's Encrypt 的证书有效期为90天,若是证书的有效期大于30天,则上面命令不会真的去更新证书的。
在浏览器输入 https://example.com 网址进行验证,通常Chrome会有一个绿色的锁以及Secure标示。php
最后若是以为所讲的东西可以帮助到你,而且但愿了解更多的知识,进行更详细的深刻的学习,欢迎加群632109190进行讨论和学习。html