linux 升级https 协议,CentOS 7 下 将http协议升级为https协议

CentOS 7 下 将http协议升级为https协议

2019-05-26 18:08:21 来源: 晴天小雨

0

摘要:只从https出现后,很多浏览器开始将http协议列入不安全清单,影响用户体验。为了进一步提升用户体验,同时加强数据安全,将http协议升级为https协议已经是一种趋势。

前言

Let’s Encrypt 的通配符证书可以免费申请,安装和使用,申请通配符证书需要 ACME v2 协议的客户端,官方推荐使用 Certbot。

Let’s Encrypt 证书只有90天的有效期。

Certbot可以自动注册账号和自动更新证书。

安装Certbot

如果使用的是EC2(弹性计算云服务器),你需要执行以下命令

yum -y install yum-utils

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

安装Certbot

sudo yum install certbot python2-certbot-nginx

自动申请证书

sudo certbot --nginx

根据终端提示:

输入邮箱地址,以备紧急更新或者安全提醒的通知

同意许可协议

是否分享你的邮箱

选择绑定的域名

是否选择重新向

申请通配符证书(可选)

sudo certbot -a dns-plugin -i nginx -d "*.example.com" -d example.com --server https://acme-v02.api.letsencrypt.org/directory

example.com替换为自己的域名

申请自动更新证书

sudo certbot renew --dry-run

定制化更新

0 0,12 * * * python -c 'import random; import time; time.sleep(random.random() * 3600)' && certbot renew

Nginx配置多个域名重定向为https

根据Certbot自动生成的Nginx配置,只要针对Nginx自动生成的server配置对if语句进行定制化修改即可

server {

if ($host = aitolearn.com) {

return 301 https://$host$request_uri;

} # 增加aitolearn.com重定向

if ($host = www.aitolearn.com) {

return 301 https://$host$request_uri;

} # managed by Certbot

listen 80 ;

listen [::]:80 ;

server_name aitolearn.com www.aitolearn.com;

return 404; # managed by Certbot

}

问题集锦

问题1:ImportError: 'pyOpenSSL' module missing required functionality. Try upgrading to v0.14 or newer.

方法:pip install pyOpenSSL==0.14

如果还是未能解决,出大招

删除所有certbot和 pyOpenSSL

yum remove certbot && pip uninstall pyOpenSSL

安装依赖

yum install -y python-devel

yum install -y openssl-devel

重新安装certbot

sudo yum install certbot python2-certbot-nginx

重新安装pyOpenSSL

pip install pyOpenSSL

问题2:Cannot uninstall 'pyOpenSSL'. It is a distutils installed project and thus we cannot accurately d...

方法:

pip show pyOpenSSL

mv pyOpenSSL-0.13.1-py2.7.egg-info pyOpenSSL-0.13.1-py2.7.egg-info.bak

pip uninstall pyOpenSSL

问题3:ImportError: No module named 'requests.packages.urllib3'

方法:pip install -U urllib3

问题4:UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 1: ordinal not in range(128)

方法:

在/usr/lib/python2.7/site-packages/目录下添加一个sitecustomize.py文件,加入内容

import sys

sys.setdefaultencoding('utf-8')

或者Nginx 配置文件中的中文注释去掉

参考资料

收藏

已收藏取消收藏

登录发表你的评论

0条评论

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值