WordPress 使用 Nginx 进行 HTTPS 连接

Table of Contents

前言

完成 WordPress 安装后,WordPress 网站与用户之间的通信是通过 HTTP(未加密)完成的。虽然 HTTP 可用于测试目的,但要在生产环境中使用,就必须切换到HTTPS。

前提条件

  • Nginx
  • Certbot
  • WordPress

安装 Certbot

				
					sudo apt-get install certbot python3-certbot-nginx -y
				
			

使用 Certbot 获取 Letsencrypt 免费证书(单域名证书)

				
					sudo certbot --nginx -d www.example.com
				
			

获取成功后,可选择让 Nginx 自动配置 HTTP 重定向 HTTPS。

使用 Certbot 获取 Letsencrypt 免费证书(泛域名证书)

				
					sudo certbot certonly --manual -d *.example.com -d example.com --agree-tos --email you@example.com --no-bootstrap --manual-public-ip-logging-ok --preferred-challenges dns-01 --server https://acme-v02.api.letsencrypt.org/directory
				
			

获取成功后,证书将会存储在 /etc/letsencrypt 目录下。接下来先在 WordPress 设置界面更改网址为 HTTPS,再重启 Nginx,此时再进入就会自动跳转到 HTTPS。

*请注意,获取的 Letsencrypt 免费证书有效期为3个月。

发表评论须遵守中华人民共和国相关法律法规。违规评论将会被删除。

Comments must subject to the relevant laws and regulations of the People’s Republic of China. Offending comments will be deleted.

发表评论

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

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理

滚动至顶部