【问题标题】:Mixed Content errors on Wordpress site with Apache VirtualHost带有 Apache VirtualHost 的 Wordpress 站点上的混合内容错误
【发布时间】:2025-12-02 12:55:02
【问题描述】:

我在 apache 上设置了从 http 到 https 的自动重定向后,在 wordpress 网站上遇到了混合内容错误。

Mixed Content: The page at 'https://example.example.com/' was loaded over HTTPS, but requested an insecure stylesheet http://example.example.com/wp-content/uploads/elementor/css/post-2612.css?ver=1481615259'. This request has been blocked; the content must be served over HTTPS

我想知道是我的 htaccess / virtualhost 问题还是代码、css 等问题。

我的 htaccess 代码如下所示:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

我的虚拟主机如下所示:

<VirtualHost *:80>
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R=301,L]
    ServerName example.example.com
    ServerAdmin hostmaster@example.com
    DocumentRoot /mnt/data/html1
    ErrorLog /mnt/data/html1/example.example.com_error.log
    CustomLog /mnt/data/html1/example.example.com_access_log combined env=!dontlog
</VirtualHost>

<VirtualHost _default_:443>
    SSLEngine on
    RewriteEngine On
    RewriteCond %{HTTPS} on
    SSLCertificateFile    /etc/httpd/sites-available/crt.crt
    SSLCertificateKeyFile /etc/httpd/sites-available/pem.pem
    ServerName example.example.com
    DocumentRoot /mnt/data/html1
    ErrorLog /mnt/data/html1/example.example.com_error.log
    CustomLog /mnt/data/html1/example.example.com_access_log combined env=!dontlog
</VirtualHost>

<Directory "/mnt/data/html1">
    AuthType Basic
    AuthName "Restricted Content"
    AuthUserFile /mnt/data/html1/.htpasswd
    Require valid-user
    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

【问题讨论】:

    标签: wordpress apache .htaccess redirect


    【解决方案1】:

    跟踪和解决所有混合内容问题可能很烦人。这是来自谷歌的优秀指南,可以有条不紊地完成它。 https://developers.google.com/web/fundamentals/security/prevent-mixed-content/fixing-mixed-content

    就我个人而言,我一直在 DNS 级别使用 cloudflare 的自动重写系统,这是完全交钥匙的,对于懒人来说是一个绝妙的技巧。

    虽然 chrome 应该识别通过 3rd 方加载的内容之间的区别(假设您有 JS 供应商库从某处提取资产,但我知道这有时会导致警告,在浏览器中查看您的网络选项卡将确定哪个出站链接正在触发问题。

    【讨论】:

    • 谢谢,我会等待更多的答案,也许我的重写配置有问题。
    • 其他人可能更擅长查看 htaccess 中的错误,但您使用 default:443> 而不是 是否有原因?尽管存在混合内容错误,但您的流量是否正确重定向?
    • 目前在mixed content errors旁边看起来还可以,您是否建议更改为&lt;VirtualHost *:443&gt;
    • 对不起,我实际上没有正确阅读问题,您可能不应该使用 default 因为它混合了 IP/命名虚拟主机定义,但我不认为那是这里的问题。实际上,您的 htacces 中似乎根本没有强制 https 的重写规则。见这里*.com/questions/4083221/…
    • 如果您想在虚拟主机定义而不是 htaccess 中使用重写,我似乎对重写规则布局一无所知。看这里,digitalocean.com/community/questions/…重写规则必须进入容器digitalocean.com/community/questions/…
    最近更新 更多