当通过https访问一个隐藏在nginx反向代理后的wordpress网站出现"mixed content"错误,其中客户端请求首先通过https到达nginx, nginx然后通过http与wordpress docker进行通讯
Mixed Content: The page at ‘’ was loaded over HTTPS, but requested an insecure script ‘’. This request has been blocked; the content must be served over HTTPS
该错误是因为浏览器是通过https协议访问的网站,但反向代理后的wordpress实际是通过http协议去加载那些静态内容,检查wp-config.php
发现有如下检测逻辑:
// If we're behind a proxy server and using HTTPS, we need to alert WordPress of that fact
// see also https://wordpress.org/support/article/administration-over-ssl/#using-a-reverse-proxy
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false) {
$_SERVER['HTTPS'] = 'on';
}
// (we include this by default because reverse proxying is extremely common in container environments)
检查nginx配置中,反向代理配置中没有任何X_Forwarded_Proto
头的定义,经了解X-Forwarded-Proto (XFP)
是一个事实上的标准首部,用来确定客户端与代理服务器或者负载均衡服务器之间的连接所采用的传输协议(HTTP 或 HTTPS)。
在nginx配置中加入以下行后解决问题
proxy_set_header X-Forwarded-Proto $scheme;