【问题标题】:Mixed content error while serving wordpress from another instance从另一个实例提供 wordpress 时出现混合内容错误
【发布时间】:2020-08-17 18:43:09
【问题描述】:

我想从https://example.com/blog 提供一个 WordPress 应用程序。问题是https://example.com 托管在另一个实例上,我将/blog 重定向到另一个实例。我使用的服务器是 Nginx。这是我的 Nginx 配置。

server {
 server_name example.com;

  location / {
   try_files $uri $uri /index.html;
  }

  location ^~ /blog {
   proxy_pass http://<IP>/blog;
   proxy_set_header X-Real-IP $remote_addr;
   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

   allow <IP>;
 }
}

由于/blog 在其他实例上运行,它给了我混合内容错误,因为代理被传递给http:IP 并且它通过https 加载。请帮我解决这个问题。

【问题讨论】:

    标签: wordpress nginx server nginx-reverse-proxy


    【解决方案1】:

    $_SERVER['HTTPS'] 需要设置为on,以防您通过 proxy_pass 访问它并通过 HTTPS 传递它。否则,WordPress 知道它已被转发,但无法检查它是通过 HTTP 还是 HTTPS 传递到外部的。将这些行添加到您的 wp-config.php 文件中:

    if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        $_SERVER['HTTPS'] = 'on';
    }
    

    请注意,如果有多个代理并且其中一个不提供 HTTPS,则您必须根据 HTTP_X_FORWARDED_FOR 实际包含的内容来设置该条件。目前,我们只检查它是否为非空,然后我们假设它应该是 HTTPS。

    【讨论】:

    • 感谢您的帮助,所有混合内容错误都消失了,但现在它提供net:: ERR_SSL_PROTOCOL_ERROR。因为它走的是这条路:https://&lt;IP&gt;/blog/wp-content/..
    猜你喜欢
    • 1970-01-01
    • 2020-02-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-11
    • 2013-05-22
    • 2021-09-13
    • 1970-01-01
    • 2015-11-26
    相关资源
    最近更新 更多