certbot https協議配置
一、獲取https證書(目前不會配萬用字元,貌似要錢)
如果是CentOS 6、7,先執行:yum install epel-release
cd /root/
wget https://dl.eff.org/certbot-auto --no-check-certificate
chmod +x ./certbot-auto
./certbot-auto -n
./certbot-auto -n只是用來安裝依賴包的,也可以跳過直接到下面的生成證書的步驟,國內VPS或伺服器上使用的話建議先修改為國內的pip源。
單域名生成證書:以下的資料夾自定義
./certbot-auto certonly --email 你的郵箱 --agree-tos --no-eff-email --webroot -w /home/wwwroot/www.vpser.net(這個是資料夾名字,自定義,下同) -d www.vpser.net
多域名單目錄生成單證書:(即一個網站多個域名使用同一個證書)
./certbot-auto certonly --email 你的郵箱 --agree-tos --no-eff-email --webroot -w /home/wwwroot/www.vpser.net -d www.vpser.net -d bbs.vpser.net
多域名多目錄生成一個證書:(即一次生成多個域名的一個證書)
./certbot-auto certonly --email 你的郵箱 --agree-tos --no-eff-email --webroot -w /home/wwwroot/vpser.com -d wap.vpser.com -d seller.vpser.com -d staff.vpser.com -d admin.vpser.com -d api.vpser.com
提示
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at
/etc/letsencrypt/live/www.vpser.net/fullchain.pem. Your cert will
expire on 2019-11-25. To obtain a new or tweaked version of this
certificate in the future, simply run certbot-auto again. To
non-interactively renew *all* of your certificates, run
"certbot-auto renew"
- If you like Certbot, please consider supporting our work by:
Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le
就是生成成功。
生成的證書會存在:/etc/letsencrypt/live/www.vpser.net/ 目錄下
二、nginx配置https對映
1.配置https
server {
listen 443 ssl;
server_name wap.vpser.com;
location / {
root /xxxx/xxxx/xxxx;
index index.html index.php index.htm;
client_max_body_size 500m;
autoindex on;
}
ssl on;
ssl_certificate /etc/letsencrypt/live/wap.vpser.com/fullchain.pem; #前面生成的證書,改一下里面的域名就行
ssl_certificate_key /etc/letsencrypt/live/wap.vpser.com/privkey.pem; #前面生成的金鑰,改一下里面的域名就行
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
2.將http對映到https
server {
listen 80;
server_name wap.vpser.com;
location / {
add_header Content-Type 'text/plain;';
root /xxx/xxx/xxx;
return 301 https://wap.vpser.com$request_uri;
}
}
三、配置自動更新
執行程式碼:crontab -e
新增定時器:
25 14 13 * * /root/certbot-auto renew --renew-by-default --renew-hook "/usr/nginx/sbin/./nginx -s reload"
任務命令書寫格式: