使用Let's Encrypt 創(chuàng)建免費證書
創(chuàng)建一個專門放證書的文件夾
mkdir acme
cd acme
下載letsencrypt 并制作
git clone https://github.com/letsencrypt/letsencrypt
cd letsencrypt
./letsencrypt-auto certonly --email xxxxx@126.com
域名可以填寫多個:
Please enter in your domain name(s)
xxx.com www.xxx.com
選擇 Place files in webroot directory (webroot)
并填寫 /usr/share/nginx/html/
- 查看證書
cd /etc/letsencrypt/live
找到自己的域名
cert.pem 服務(wù)器證書
privkey.pem 是證書私鑰
- 修改配置文件
server {
listen 443;
listen 80;#用戶習慣用http訪問先较,加上80敞恋,后面通過497狀態(tài)碼讓它自動跳到443端口
server_name www.xxx.com;
ssl on;
#前面生成的證書祝钢,改一下里面的域名就行顶瞒,不建議更換路徑
ssl_certificate //etc/letsencrypt/live/www.xxx.com/fullchain.pem;
#前面生成的密鑰,改一下里面的域名就行话浇,不建議更換路徑
ssl_certificate_key /etc/letsencrypt/live/www.xxx.com/privkey.pem;
location / {
#try_files $uri $uri/ /index.php$is_args$args;
index index.php index.html index.htm;
}
#讓http請求重定向到https請求
error_page 497 https://$host$uri?$args;
}
- 制作定時任務(wù)
將 命令添加到 crontab 中
vi /etc/crontab
0 0 1 * * root sh /etc/nginx/acme/letsencrypt/letsencrypt-auto renew && nginx -s reload >/dev/null 2>&1
啟動定時任務(wù)
service crond start