You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WordPress部署HTTPS域名后混合内容及登录异常问题求助

解决方案

1. 配置Nginx强制HTTP跳转至HTTPS

添加监听80端口的server块,将所有HTTP请求重定向到HTTPS,避免登录跳转至不安全页面:

server {
    listen 80;
    server_name www.triadmathtutor.com;
    return 301 https://$server_name$request_uri;
}

2. 修正Nginx中WordPress的HTTPS环境传递

在现有443 server块的location ~ \.php$段中,添加HTTPS标识参数,确保WordPress识别当前为HTTPS环境:

location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    include fastcgi_params;
    fastcgi_pass unix:/run/php/php7.4-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_script_name;
    # 新增以下两行
    fastcgi_param HTTPS on;
    fastcgi_param HTTP_X_FORWARDED_PROTO https;
}

3. 修改WordPress站点URL(无需后台)

直接编辑WordPress根目录下的wp-config.php,在/* That's all, stop editing! Happy publishing. */之前添加:

define('WP_HOME', 'https://www.triadmathtutor.com');
define('WP_SITEURL', 'https://www.triadmathtutor.com');

这会强制WordPress使用HTTPS加载所有静态资源,解决混合内容报错。

4. 可选:批量替换数据库中的HTTP链接

若仍有旧HTTP资源残留,通过MySQL命令批量替换:

  1. 登录MySQL:mysql -u 数据库用户名 -p
  2. 切换到WordPress数据库:USE 你的数据库名称;
  3. 执行替换命令(表前缀非wp_需替换为实际前缀):
UPDATE wp_posts SET post_content = REPLACE(post_content, 'http://www.triadmathtutor.com', 'https://www.triadmathtutor.com');
UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, 'http://www.triadmathtutor.com', 'https://www.triadmathtutor.com');

完成所有配置后,重启Nginx服务:sudo systemctl restart nginx

内容的提问来源于stack exchange,提问作者user280339

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 11:52:36