环境
ubuntu16.04
下载/安装/运行
下载 : https://dl.eff.org/certbot-auto
添加权限: chmod a+x certbot-auto
运行: ./certbot-auto certonly -d "*.weihailan.com" --manual --preferred-challenges dns-01 --server https://acme-v02.api.letsencrypt.org/directory
如果出现报错:
OSError: Command /opt/eff.org/certbot/venv/bin/python2.7 - setuptools pkg_resources pip wheel failed with error code 2
执行下面的操作 :
sudo apt-get install letsencryp
apt-get purge python-virtualenv python3-virtualenv virtualenv
pip install virtualenv
然后重新执行前一条命令
修改 nginx 的配置
运行后 会在 /etc/letsencrypt/live/xxx.com 目录下生成一些文件,然后添加nginx配置
# 使用 ssl 的站点,自动跳转和 https 站点的配置
server {
listen 80;
server_name xxx.com www.xxx.com;
# 跳转到 https 站点
rewrite ^(.*)$ https://$host$1 permanent;
# root /data/wwwroot/xxx;
# index index.html;
}
server {
listen 443 http2 ssl;
server_name xxx.com www.xxx.com;
root /data/wwwroot/xxx;
index index.html;
# 启用 ssl
ssl on;
ssl_certificate /etc/letsencrypt/live/xxx.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/xxx.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/xxx.com/chain.pem;
}
最后不要忘了打开443端口供https站点使用
普通的 webroot方式可使用命令:
certbot certonly --webroot -d www.xxx.com -w /data/wwwroot/xxx
注意:
同 ip 每3小时只允许10个证书的限制
更详细步骤可参考: https://www.hi-linux.com/posts/6968.html