阿里云Ubuntu16.04配置Let's encrypt通配符证书

本文详细介绍了如何在阿里云Ubuntu16.04环境中,使用Certbot客户端配置Let's encrypt的SSL通配符证书。包括配置环境、申请证书、解决pip升级问题、配置证书以及更新证书的步骤,旨在帮助用户实现免费且安全的HTTPS服务。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

阿里云 Ubuntu16.04 配置 Let’s encrypt 通配符证书

参考文章:
快速配置Let’s encrypt通配符证书
pip 10.0.0 BUG 解决方案
解决python2.7 - pip wheel failed with error code 2 问题

letencrypt 是目前免费颁发 ssl 证书的机构,通过 certbot 客户端可以快速申请 90 天免费的证书,到期之后通过再次申请来达到永久使用的目的。

下面主要分享一下在阿里云ubuntu16.04下配置证书的过程

配置环境及域名信息

操作系统: 阿里云ubuntu16.04
web服务器:nginx/1.13.6
域名:*.927youyu.com, 927youyu.com

配置步骤

1. 获取Certbot

# 下载最新的cerbot
wget https://dl.eff.org/certbot-auto

2. 执行申请证书命令

./certbot-auto certonly  -d "*.927youyu.com" -d "927youyu.com" --manual --preferred-challenges dns-01  --server https://acme-v02.api.letsencrypt.org/directory --email=youremail@test.com

参数说明:

  • -certonly 表示安装模式,Certbot 有安装模式和验证模式两种类型的插件

  • -manual 表示手动安装插件,Certbot 有很多插件,不同的插件都可以申请证书,用户可以根据需要自行选择。

  • -d 为哪些主机申请证书,如果是通配符,输入 *.927youyu.com(替换为自己的域名)

  • -preferred-challenges 使用 DNS 方式校验域名所有权

  • -server Let’s Encrypt ACME v2 版本使用的服务器不同于 v1 版本,需要显示指定

执行错误解决

certbot脚本基于python2,当系统里有python2 和python3时,会有报错:

OSError: Command /root/.local/share/letsencrypt/bin/python2.7 -setuptools pkg_resources pip wheel failed with error code 2
Let's Encrypt returned an error status. Aborting.

首先升级pip尝试解决

pip -V
pip install --upgrade pip
pip -V
# 此处报错
Traceback (most recent call last): 
File “/usr/bin/pip3”, line 9, in 
from pip import main

解决pip报错:
修改 /usr/bin/pip 文件:

from pip import main
if __name__ == '__main__':
    sys.exit(main())

改为:

from pip import __main__
if __name__ == '__main__':
    sys.exit(__main__._main())

重新执行申请证书命令,发现依然报错,尝试重新安装virtualenv环境:
卸载

apt-get purge python-virtualenv python3-virtualenv virtualenv

安装:

pip install virtualenv

重新执行申请证书命令,成功出现确认申请信息

确认申请信息:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator manual, Installer None
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): hubinqiang@126.com

-------------------------------------------------------------------------------
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
-------------------------------------------------------------------------------
(A)gree/(C)ancel: A

-------------------------------------------------------------------------------
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about EFF and
our work to encrypt the web, protect its users and defend digital rights.
-------------------------------------------------------------------------------
(Y)es/(N)o: Y
Obtaining a new certificate
Performing the following challenges:
dns-01 challenge for hubinqiang.com
dns-01 challenge for hubinqiang.com

-------------------------------------------------------------------------------
NOTE: The IP of this machine will be publicly logged as having requested this
certificate. If you're running certbot in manual mode on a machine that is not
your server, please ensure you're okay with that.

Are you OK with your IP being logged?
-------------------------------------------------------------------------------
(Y)es/(N)o: Y

-------------------------------------------------------------------------------

DNS验证域名所有权,在域名 DNS 解析中添加 TXT记录:

-------------------------------------------------------------------------------
Please deploy a DNS TXT record under the name
_acme-challenge.hubinqiang.com with the following value:

kC-QHSWO1LdIeyIs7VQ66sTAyioISnfzIJU0bXgo-Z8

Before continuing, verify the record is deployed.
-------------------------------------------------------------------------------
Press Enter to Continue

-------------------------------------------------------------------------------
Please deploy a DNS TXT record under the name
_acme-challenge.hubinqiang.com with the following value:

6XnGyee8W48QfRl61m_18aRs8rfvn4T8kKzQil0IYw4

Before continuing, verify the record is deployed.
-------------------------------------------------------------------------------
Press Enter to Continue
Waiting for verification...
Cleaning up challenges

确认生效后回车会有如下提示:

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/hubinqiang.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/hubinqiang.com/privkey.pem
   Your cert will expire on 2018-08-12. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot-auto
   again. To non-interactively renew *all* of your certificates, run
   "certbot-auto renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

进入/etc/letsencrypt/live/927tour.com/中可以看到几个文件,cert.pem、chain.pem、fullchain.pem、privkey.pem,说明已经成功获取证书和密钥

3. 配置证书

请根据自己的服务器信息做ssl配置,这里就不赘述。配置之后重启服务器测试是否成功

4. 更新证书

letsencrypt 默认证书时效为90天,可以通过命令重新申请证书

certbot-auto renew
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值