您的位置:首页 > 理论基础 > 计算机网络

CentOS7&Nginx环境Let`s Encrypt (HTTPS)证书获取

2017-07-18 11:18 309 查看

CentOS7&Nginx环境Let`s Encrypt (HTTPS)证书获取

HTTPS证书获取步骤

### 拥有一个可用域名

### CentOS7配置nginx

### 安装并配置Certbot

拥有一个可用域名

通过阿里云或其它途径购买即可

建议操作之前先更新一下pip版本,以免因此出错

pip install –upgrade pip

CentOS7配置nginx

#/etc/nginx/conf.d/default.conf
server {
listen 80;
server_name www.wppele.com; # 必须是域名,后面certbot配置时会自动关联这个域名

location / {
proxy_pass http://127.0.0.1:5000; # 这里是指向 gunicorn host 的服务地址
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

}


修改完毕后记得重启nginx或者重载nginx配置

nginx重启:
systemctl restart nginx


nginx配置重载:
nginx -s reload


安装并配置Certbot

Certbot是Let’s Encrypt发布的一款工具,用于方便人们申请、续订和部署https免费证书。

Certbot安装参考网址:https://certbot.eff.org/#centosrhel7-nginx

按照步骤一步步运行命令即可

1.安装依赖环境

yum -y install yum-utils


yum-config-manager --enable rhui-REGION-rhel-server-extras rhui-REGION-rhel-server-optional


2.安装certbot-nginx

yum install certbot-nginx


3.运行certbot对nginx的配置插件

certbot --nginx


这条命令如果成功运行,则会出现配置流程,按照步骤填写(1)邮箱->(2)A->(3)Y->(4)回车->(5)选择是否可以http与https同时访问,1是允许同时访问,2是所有访问通过https

这条命令如果不能成功运行,可能出现的问题有:

nginx中配置的域名不存在(安装错误中会有明显提示)

certbot error ‘pyOpenSSL’ module missing required functionality. Try upgrading to v0.14 or newer.错误提示。引起这个提示的原因是找不到pyOpenSSL模块或者pyOpenSSL模块的版本低于v0.14。

解决方法是下载安装新版本pyOpenSSL:

wget ftp://mirror.switch.ch/pool/4/mirror/centos/7.3.1611/cloud/x86_64/openstack-liberty/common/pyOpenSSL-0.15.1-1.el7.noarch.rpm[/code] 
rpm -Uvh pyOpenSSL-0.15.1-1.el7.noarch.rpm


4.模拟自动更新证书(Let`s Encrypt免费证书默认90天到期)

certbot renew –dry-run

#出现下面一段话就证明模拟成功
Congratulations, all renewals succeeded. The following certs have been renewed:
/etc/letsencrypt/live/www.wppele.com/fullchain.pem (success)
** DRY RUN: simulating 'certbot renew' close to cert expiry
**          (The test certificates above have not been saved.)


5.如果通过上面命令模拟成功,则以后可通过下面命令更新证书

certbot renew

6.为了方便,我们可以将自动更新设置为系统定时任务

运行:crontab -e

30 1 * * 1 /usr/bin/certbot renew >> /var/log/le-renew.log 每周一凌晨1点30分自动更新证书

运行记录可到/var/log/le-renew.log下查看
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息