WordPress安装(二):使用Certbot配置SSL证书

翻译自

https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-18-04

介绍

这篇文章介绍了如何使用Certbot软件来为网站配置SSL证书,以及如何实现对http请求的转发。如果使用了反向代理,并且反向代理服务器已经配置好了相关的证书和转发,那么就不需要自己再配置了。

准备工作

  • 配置好LEMP的ubuntu服务器(参照这篇文章)和域名( 本文以xxx.yyy为例)。

第一步:安装Certbot

使用apt安装Certbot,其中添加repository时需要回车确认:

sudo add-apt-repository ppa:certbot/certbot
sudo apt install python-certbot-nginx

第二步:使用Certbot安装SSL证书

运行以下命令为网站安装SSL证书:

sudo certbot --nginx -d xxx.yyy -d www.xxx.yyy

安装成功后,Certbot会询问是否转发http请求:

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
-------------------------------------------------------------------------------
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
-------------------------------------------------------------------------------
Select the appropriate number [1-2] then [enter] (press 'c' to cancel):

根据实际情况选择后,会提示安装成功,并且显示已安装的证书的位置。

第三步:检测Certbot自动续期功能

Certbot会自动对SSL证书进行续期,运行以下命令可以模拟一次证书的续期功能:

sudo certbot renew --dry-run

如果没有任何错误信息,那么代表已经成功为网站安装了SSL证书。

留下评论

您的电子邮箱地址不会被公开。 必填项已用*标注