【问题标题】:403 errors for images only on newly added ServerAlias仅在新添加的 ServerAlias 上的图像出现 403 错误
【发布时间】:2025-12-19 04:25:11
【问题描述】:

我有两个网络服务器在同一台机器上运行,地址如下:

internal.myservername.com

test.myservername.com

测试站点(在某些页面上)从内部​​站点提取图像,并且运行良好。现在我们已经完成了测试,我想将测试域添加/更改为主站点,所以我将 myservername.com 的 apache 服务器别名添加到测试站点,但是虽然所有页面都可以正常工作,但来自内部的任何图像都会没有显示在那个地址上,导致 403 错误:

[access_compat:error] AH01797: client denied by server configuration

我还尝试将 myservername.com 设置为自己的域,并尝试将其设置为测试站点上的主要名称(以 test 为别名)。在所有情况下,test.myservername.com 都能正常工作并正确显示图像,而 myservername.com 则不能(导致这些嵌入图像出现所有 403 错误)。

我检查了所有配置,没有发现任何问题。我的 .htaccess 文件或 conf 文件中没有任何特定于“测试”的内容。我被难住了。

我可能还应该提到我在 Mac OS Sierra 服务器上运行。 (服务器版本:Apache/2.4.23 (Unix))

按照要求的详细信息进行更新:

  1. img标签:图片标签没有什么特别的,都是用完整的url调用的,即

<img src="http://internal.myservername.com/images/imagename.jpg" />

我还应该补充一点,如果我获取确切的 src url 并将其单独粘贴到浏览器中,图像将加载。它仅嵌入在拒绝加载的页面中。 (并且仅在主域上,测试嵌入在 img 标签中可以正常工作)

  1. 而test/main conf的设置是:

    <VirtualHost 127.0.0.1:34580>
    ServerName http://test.myservername.com:80
    ServerAdmin admin@example.com
    DocumentRoot "/Library/Server/Web/Data/Sites/myservername.com/plugins/mywebsite"
    DirectoryIndex index.php home.php index.html
    CustomLog /var/log/apache2/access_log combinedvhost
    ErrorLog /var/log/apache2/error_log
    <IfModule mod_ssl.c>
        SSLEngine Off
        SSLCipherSuite "HIGH:MEDIUM:!MD5:!RC4:!3DES"
        SSLProtocol -all +TLSv1 +TLSv1.1 +TLSv1.2
        SSLProxyEngine Off
        SSLProxyProtocol -all +TLSv1 +TLSv1.1 +TLSv1.2
    </IfModule>
    <IfModule mod_secure_transport.c>
        MSTEngine Off
        MSTCipherSuite HIGH, MEDIUM
        MSTProtocolRange TLSv1.2 TLSv1.2
        MSTProxyEngine On
        MSTProxyProtocolRange TLSv1.2 TLSv1.2
    </IfModule>
    <Directory "/Library/Server/Web/Data/Sites/myservername.com/plugins/mywebsite">
        Options All -Indexes +ExecCGI +Includes +MultiViews
        AllowOverride All
        <IfModule mod_dav.c>
            DAV Off
        </IfModule>
        <IfDefine !WEBSERVICE_ON>
            Require all denied
            ErrorDocument 403 /customerror/websitesoff403.html
        </IfDefine>
    </Directory>
    ServerAlias myservername.com
    

  2. 以及内部配置:

    <VirtualHost 127.0.0.1:34580> ServerName http://internal.myservername.com:80 ServerAdmin admin@example.com DocumentRoot "/Library/Server/Web/Data/Sites/myservername.com" DirectoryIndex index.php CustomLog /var/log/apache2/access_log combinedvhost ErrorLog /var/log/apache2/error_log <IfModule mod_ssl.c> SSLEngine Off SSLCipherSuite "HIGH:MEDIUM:!MD5:!RC4:!3DES" SSLProtocol -all +TLSv1 +TLSv1.1 +TLSv1.2 SSLProxyEngine Off SSLProxyProtocol -all +TLSv1 +TLSv1.1 +TLSv1.2 </IfModule> <IfModule mod_secure_transport.c> MSTEngine Off MSTCipherSuite HIGH, MEDIUM MSTProtocolRange TLSv1.2 TLSv1.2 MSTProxyEngine On MSTProxyProtocolRange TLSv1.2 TLSv1.2 </IfModule> <IfModule mod_headers.c> <filesmatch "^.*www.*\.jpg$"> Header set Cache-Control "max-age=2678400, public" </filesmatch> </IfModule> <Directory "/Library/Server/Web/Data/Sites/myservername.com"> Options All -Indexes +ExecCGI +Includes +MultiViews AllowOverride All Require all granted <IfModule mod_dav.c> DAV Off </IfModule> <IfDefine !WEBSERVICE_ON> Require all denied ErrorDocument 403 /customerror/websitesoff403.html </IfDefine> </Directory> </VirtualHost>

【问题讨论】:

  • 我怀疑这个问题可能与您调用图像的方式以及响应图像的服务器有关,而不是与附加域的设置有关。但这只是一种狂野的直觉。如果您同时发布 vhost.conf 文件以及示例 HTML 源代码示例 &lt;img&gt; 标记和/或图像请求的 Network 选项卡输出,那肯定会有所帮助。
  • 已更新请求的信息,感谢您的评论。

标签: apache http-status-code-403


【解决方案1】:

哎呀,我刚刚弄清楚是什么原因造成的,我采取了以下步骤来解决这个问题:

  1. 因为我的错误发生在 mod_access_compat 中,所以我关闭了该模块以查看是否有任何变化

  2. 这导致了更清晰的 error_log 消息,指出内部站点上我的图像文件夹中的 .htaccess 文件存在问题(这是由其他人设置的,直到出现错误我才知道存在给我看)

  3. 那个 .htaccess 文件包含允许我的测试站点提取图像的指令,但不是新域,所以一旦我将它添加到文件中,一切都已修复。

对于那些想知道指令是什么的人:

SetEnvIfNoCase Referer "^http://test.myservername.com/" locally_linked=1
SetEnvIfNoCase Referer "^http://test.myservername.com$" locally_linked=1
SetEnvIfNoCase Referer "^http://internal.myservername.com/" locally_linked=1
SetEnvIfNoCase Referer "^http://internal.myservername.com$" locally_linked=1
SetEnvIfNoCase Referer "^$" locally_linked=1
<FilesMatch "\.(gif|png|jpe?g)$">
  Order Allow,Deny
  Allow from env=locally_linked
</FilesMatch>

通过添加以下两行,它现在可以工作了:

SetEnvIfNoCase Referer "^http://myservername.com/" locally_linked=1
SetEnvIfNoCase Referer "^http://myservername.com$" locally_linked=1

【讨论】:

    最近更新 更多