一键安装WordPress应用使用Let\'s Encrypt SSL
Hrh
・3 分钟阅读
介绍
Let's Encrypt是一个提供免费tls/ssl证书的证书颁发机构服务,安装过程由Certbot简化,Certbot是一个软件客户端,可以自动执行大部分安装过程,本教程展示了如何在One-Click Wordpress应用程序上安装加密SSL证书。
前提条件
本教程假设你已经部署了One-Click Wordpress应用,有一个指向你的服务器的域名,并已作为root登录。
步骤1:更新Nginx站点配置文件
首先要做的是更新Nginx站点配置文件中的服务器名,停止Nginx服务。
service nginx stop
编辑wordpress_http.conf
和wordpress_https.conf
Nginx配置文件,查找server_name _
并将_
替换为你的域名。
nano /etc/nginx/conf.d/wordpress_http.conf
# Replace the underscore"_" after server_name to your domain name.
server_name example.com www.example.com
nano /etc/nginx/conf.d/wordpress_https.conf
# Replace the underscore"_" after server_name to your domain name.
server_name example.com www.example.com`
第二步:下载Certbot
由于Certbot未随Ubuntu 16.04一起安装,因此需要获取Certbot包的副本。
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install python-certbot-nginx
将下载并安装certbot包。
步骤3:获取并安装SSL证书
Certbot通过提供交互式安装程序自动获取证书,运行Certbot安装程序,将Nginx指定为你的Web服务器。
certbot --nginx --redirect
提示时输入你的电子邮件地址,这会用于向你发送有关更新和安全性的通知,输入"A"以同意服务条款。
步骤4:更新Nginx配置以强制使用SSL
为了强制使用HTTPS,你需要编辑wordpress_http.conf
配置文件。
nano /etc/nginx/conf.d/wordpress_http.conf
将以下行添加到server
块。
if ($scheme = http) {
return 301 https://$server_name$request_uri;
}
保存文件并启动Nginx服务器。
service nginx start
你的Wordpress网站现在使用Let's EncryptSSL证书保护。
更新SSL证书
Let's EncryptSSL证书颁发有效期为90天的SSL证书,为了避免证书错误,你必须在证书过期前续订证书,Certbot还可以自动完成续订过程。
certbot renew
这将使你的证书再延长90天