版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/a6383277/article/details/52326552
系统环境
ubuntu 14.04 以及以上 (以下按道理也可以)
nginx
本文的命令都是 sudo
权限下进行的操作
安装 letsencrypt
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install python-certbot-nginx
sudo certbot --nginx -d example.com -d www.example.com
官方推荐每天自动进行证书续期。 【证书有效期为90天】
crontab -e
添加:
0 3 * * * /usr/bin/certbot renew --quiet --nginx
如果是下载的安装包
https://github.com/certbot/certbot/releases
解压后:
# apache server
./certbot-auto --apache -d example.com -d www.example.com -d other.example.net
# nginx server
./certbot-auto --nginx -d example.com -d www.example.com -d other.example.net
自动续期:
crontab -e
添加
0 3 * * * /path/to/letsencrypt/crontab-auto renew --nginx
Nginx 配置
server {
listen 443 ssl;
index index.html index.htm index.nginx-debian.html;
ssl_certificate /etc/letsencrypt/live/apying.com/fullchain.pem; #替换相关证书
ssl_certificate_key /etc/letsencrypt/live/apying.com/privkey.pem; #替换相关证书
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers AES256+EECDH:AES256+EDH:!aNULL;
server_name domain.com www.domain.com;
location / {
try_files $uri $uri/ =404;
root /var/www/apying;
index index.html;
}
#其他的路径映射自己填
}
server {
listen 80;
server_name domain.com www.domain.com;
return 301 https://$host$request_uri;
}
用自己的域名替换上述的 domain.com
等就ok了。
重启nginx
service nginx restart