首頁  >  文章  >  運維  >  nginx如何防止ssl憑證過期

nginx如何防止ssl憑證過期

藏色散人
藏色散人原創
2019-08-27 10:50:587706瀏覽

nginx如何防止ssl憑證過期

nginx如何防止ssl憑證過期?

nginx配置免費SSL憑證及憑證定時更新

環境contos 6,憑證發行Let's Encrypt

憑證產生前提是網域名稱是可用的,即已經備案通過並且有DNS解析到了具體IP

1、安裝epel,

>yum install epel-release

2、下載certbot證書生成工具certbot-auto

>wget https://dl.eff.org/certbot-auto --no-check-certificate

3 、安裝工具的依賴

>chmod +x certbot-auto
>./certbot-auto -n

4、產生憑證

單網域:

>./certbot-auto certonly --email my@163.com --agree-tos --no-eff-email --webroot -w /usr/local/nginx/html/xue/ -d www.xue37.cn

注意:取代郵箱、網站目錄和網域

多網域:

>./certbot-auto certonly --email my@163.com --agree-tos --no-eff-email --webroot -w /usr/local/nginx/html/xue/ -d www.xue37.cn -d xue37.cn

憑證產生在/etc/letsencrypt/live/www.xue37.cn/目錄下(具體產生位址執行完指令有提示訊息)

5、憑證延期(因為憑證有效期限為90天)

certbot-auto工具支援憑證延期操作,因此可以使用crontab定時任務定時自動延期

>0 3 * * * /root/certbot-auto renew --disable-hook-validation --renew-hook "/usr/local/nginx/sbin/nginx -s reload"

每天3點進行憑證延期,crontab表達式自己可以百度

注意:

自己可以先單獨執行一下:

/root/certbot-auto renew --disable-hook-validation --renew-hook "/usr/local/nginx/sbin/nginx -s reload"

我這裡提示The following certs are not due for renewal yet,表示憑證未到期,沒有其他錯誤。因此為了防止憑證失效時間過久,這裡可以設定為每天進行延期操作

#6、nginx增加憑證設定

server
{
listen 443 ssl;
server_name www.xue37.cn;     ##这里是你的域名
ssl_certificate /etc/letsencrypt/live/www.xue37.cn/fullchain.pem;    #前面生成的证书,改一下里面的域名就行
ssl_certificate_key /etc/letsencrypt/live/www.xue37.cn/privkey.pem;   #前面生成的密钥,改一下里面的域名就行
ssl_ciphers ECDHE-RSA-AES256-SHA384:AES256-SHA256:RC4:HIGH:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!AESGCM;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
access_log /data/application/logs/xue.access.log main;
location ^~ /bot {
proxy_pass http://xue-server;
include proxy-params.conf;
}
location / {
root html/xue;
index index.html index.htm;
}
location = /50x.html {
root html;
}
}

7、設定80埠301到443

#修改nginx設定:

server
{
listen 80;
server_name localhost;
location /.well-known/ {
add_header Content-Type 'text/plain;';
root /usr/local/nginx/html/xue;
}
location / {
return 301 https://www.xue37.cn$request_uri;
}
}

注意:nginx修改後需要重新啟動:/usr/local/nginx/sbin/nginx -s reload

注意:nginx設定需要處理

location ~ /\.
{
deny all;
}

這段設定刪掉或註解掉或在這段設定前面加上(如果沒有這段設定請忽略)

location ~ /.well-known {
allow all;
}

更多Nginx相關技術文章,請造訪Nginx使用教學欄位進行學習!

以上是nginx如何防止ssl憑證過期的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn