仅在新添加的 ServerAlias 上的图像出现 403 错误

403 errors for images only on newly added ServerAlias

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

internal.myservername.com

test.myservername.com

测试站点(在某些页面上)从内部​​站点提取图像,并且运行完美。现在我们已经结束测试,我想 add/change 测试域作为主站点,所以我将 myservername.com 的 apache 服务器别名添加到测试站点,但是尽管所有页面都可以工作,但是任何来自内部的图像不会显示在该地址上,从而导致 403 错误:

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

我也尝试过将 myservername.com 设置为自己的域,并尝试将其设为测试站点的主要名称(test 是别名)。在所有情况下,test.myservername.com 继续正常工作并正确显示图像,而 myservername.com 不会(导致这些嵌入图像的所有 403 错误)。

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

我可能还应该提到我 运行 在 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>

呃,我刚刚弄清楚是什么原因造成的,下面是我采取的解决步骤:

  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