类别:技术积累 / 日期:2025-11-19 / 浏览:38 / 评论:0
安装Wordpress后使用HTTPS访问,可能会出现页面错乱问题,在浏览器控制台显示类似如下错误提示:
Blocked loading mixed active content “http://9icode.com/wp-includes/css/dashicons.min.css?ver=6.3.1” Blocked loading mixed active content “http://9icode.com/wp-includes/css/admin-bar.min.css?ver=6.3.1” Blocked loading mixed active content “http://9icode.com/wp-includes/css/dist/block-library/style.min.css?ver=6.3.1” Blocked loading mixed active content “http://9icode.com/wp-content/themes/bloghash/assets/css/swiper-bundle.min.css?ver=6.3.1” Blocked loading mixed active content “http://9icode.com/wp-content/themes/bloghash/assets/css/all.min.css?ver=5.15.4” Blocked loading mixed active content “http://9icode.com/wp-content/themes/bloghash/assets/css/style.min.css?ver=1.0.25” Blocked loading mixed active content “http://9icode.com/wp-content/uploads/bloghash/dynamic-styles.css?ver=1761397781” Blocked loading mixed active content “http://9icode.com/wp-includes/js/jquery/jquery.min.js?ver=3.7.0” Loading failed for the <script> with source “http://en.9icode.com/wp-includes/js/jquery/jquery.min.js?ver=3.7.0” Blocked loading mixed active content “http://en.9icode.com/wp-includes/js/jquery/jquery-migrate.min.js?ver=3.4.1”
原因是部分CSS和JS文件在HTTPS访问时,仍然是HTTP地址,由于浏览器的CSP策略,HTTPS不能HTTP资源,解决方案是在wp-config.php开头添加如下行:
define('FORCE_SSL_ADMIN', true);
$_SERVER['HTTPS'] = 'on';对于其它第三方插件的HTTPS问题可以安装“SSL Insecure Content Fixer”,设置“Fix insecure content”为“Capture”、“Ignore external sites”为“Only fix content pointing to this WordPress site”、“HTTPS detection”为“HTTP_X_FORWARDED_PROTO (e.g. load balancer, reverse proxy, NginX)”。
发表评论 / 取消回复