我在 https 下运行的服务器 Web 上安装了新版本的 WordPress。
我将两个 siteurl 和 home 选项值更改为我的 https://mysiteweb.com
我将以下值添加到我的 wp-config.php 中
define( 'WP_SITEURL', 'https://' . $_SERVER['HTTP_HOST'] . '/' );
define( 'WP_HOME', 'https://' . $_SERVER['HTTP_HOST'] . '/' );
define( 'WP_CONTENT_DIR', dirname(__FILE__) . '/wp-content' );
define( 'WP_CONTENT_URL', 'https://mysiteweb.com/wp-content' );
define( 'WP_PLUGIN_DIR', dirname(__FILE__) . '/wp-content/mydir/plugins' );
define( 'WP_PLUGIN_URL', 'https://mysiteweb.com/wp-content/mydir/plugins' );
但是我对于所有 css 和 javascript 文件加载仍然出现相同的错误:
Mixed Content: The page at 'https://mysiteweb.com/' was loaded over HTTPS, but requested an insecure script 'http://mysiteweb.com/wp-includes/js/wp-emoji-release.min.js?ver=5.4.2'. This request has been blocked; the content must be served over HTTPS.
我通过编辑 wp-config.php 解决了我的问题:
$_SERVER['HTTPS']='on';
按 CRTL + U 并检查您的页面源是否有 HTTP,找到加载 HTTP 的位置后,将其替换为 HTTPS,通常问题是某些图像或徽标未正确加载/硬编码到 HTTP 中。
另外你为什么使用 $_SERVER['HTTP_HOST'] ?而不是只写你的域名。 我发现您不需要在域的最后部分使用反斜杠,这可能是个问题。
define( 'WP_SITEURL', 'https://example.com' );
define( 'WP_HOME', 'https://example.com' );
并且您不需要使用您定义的其他部分。
我浏览了该文件
wp-config.php
并发现:
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false) {
$_SERVER['HTTPS'] = 'on';
}
将
X-Forwarded-Proto
设置为 https
。如果您使用 nginx,配置可以是:
server {
listen 443 ssl;
server_name myblog.com;
location / {
proxy_pass http://wordpress/;
proxy_redirect http://wordpress/ https://myblog.com/;
proxy_set_header Host myblog.com;
proxy_set_header X-Forwarded-Proto https;
}
}
直接设置
$_SERVER['HTTPS']='on';
到文件wp-config.php
。