首页 > 代码库 > Let's Encrypt: 为CentOS/RHEL 7下的nginx安装https支持-具体案例
Let's Encrypt: 为CentOS/RHEL 7下的nginx安装https支持-具体案例
环境说明:
centos 7nginx 1.10.2
前期准备
软件安装
yum install -y epel-releaseyum install -y certbot
创建目录及链接
方法1:在网站根目录下创建一个.well-known的目录方法2:mkdir -p /usr/local/nginx/cert/.well-knownln -s /usr/local/nginx/cert/.well-known /data/www/example.com/.well-knownln -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.pemchain.pemfullchain.pemprivkey.pem特别要注意,这条命令只会将生成的证书放在这个目录,不会有一个/etc/letsencrypt/live/test.example.com/目录,test.example.com的证书和example.com的证书放在一起了,具体看后面的nginx配置。
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/nullLet‘s Encrypt 的证书有效期为90天,如果证书的有效期大于30天,则上面命令不会真的去更新证书的。
https测试
在浏览器输入 https://example.com 网址进行验证,一般Chrome会有一个绿色的锁以及Secure标示。
最后如果觉得所讲的东西能够帮助到你,并且希望了解更多的知识,进行更详细的深入的学习,欢迎加群632109190进行讨论和学习。
Let's Encrypt: 为CentOS/RHEL 7下的nginx安装https支持-具体案例
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。