前言:在使用Frp对WordPress进行穿透时,可能会遇到以下两个问题:

网站首页能正常访问,但样式丢失。浏览器查看网络情况,发现样式请求依然是HTTP资源。
管理后台无法访问,提示重定向次数过多。
为了解决这些问题,可以按照以下步骤进行操作。

方案一

错误原因:

nginx代理的https页面中加载的内容使用的http协议导致报错。

解决方法:

增加add_header Content-Security-Policy "upgrade-insecure-requests" 将http协议升级为https。

server {
listen       80;
listen  [::]:80;
server_name test.example.cn;
listen 443 ssl;
charset utf-8;
ssl_certificate /www/server/panel/vhost/nginx/frpssl/example.cn.pem;
ssl_certificate_key /www/server/panel/vhost/nginx/frpssl/example.cn.key;
if ($server_port !~ 443){
    rewrite ^(/.*)$ https://$host$1 permanent;
}
location / {
    proxy_set_header      X-Forwarded-Proto https;
    proxy_set_header      X-Forwarded-Port 443;
    add_header Content-Security-Policy "upgrade-insecure-requests";
    proxy_set_header Host $host;
    proxy_pass http://127.0.0.1:端口;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
}

}

方案二

在wp网站根目录的wp-config.php里加入:

define('WP_HOME', 'http://'.$_SERVER ['HTTP_HOST']); 
define('WP_SITEURL', 'http://'.$_SERVER ['HTTP_HOST']);

强制HTTP,就可以登录后台,然后在安装插件:

SSL 不安全内容修复器

进入插件设置,先择简单修复

简单修复

然后选择HTTPS检测
选择检测

保存更改即可。

最后修改:2024 年 06 月 09 日
如果觉得我的文章对你有用,请随意赞赏