环境
docker镜像:wordpress:php7.4-apache
nginx: 1.19.8
nginx配置:
#强制https重定向
if ($server_port = 80) {
return 301 https://$server_name$request_uri;
}
#反向代理到容器apache端口
location / {
proxy_pass http://xxx.xxx.xxx.xxx:port;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
wordpress安装插件"HTTPS Redirection"
1.初次设置会先配置短链接,有几种格式选择,日期,或者名字等等,这里已经设置过了,没有截图(设置完保存下),仅展示设置后的后续设置(当前只能看到的设置页面),勾选以下配置:
2.进入网站根目录,配置.htaccess文件
原有文件需修改部分:
# BEGIN HTTPS Redirection Plugin
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
# END HTTPS Redirection Plugin
改为如下:
# BEGIN HTTPS Redirection Plugin
# END HTTPS Redirection Plugin
数据库静态文件地址url改为https
域名改为自己的域名:
UPDATE wp_posts SET post_content = replace( post_content, 'http://www.example.com','https://www.example.com');
设置完以上网站就可以正常访问了