简体   繁体   English

使用别名和反向代理时,Apache 2.4压缩无法正常工作

[英]Apache 2.4 compression not working when using alias and reverse proxy

Problem: I have an alias directory for a url sub path that pulls static data. 问题:我有一个用于提取静态数据的url子路径的别名目录。 I can get this to gzip compress just fine. 我可以得到这个gzip压缩就好了。 However, when I add proxy to other paths and add an exception for my static data, compression stops. 但是,当我将代理添加到其他路径并为我的静态数据添加例外时,压缩会停止。

Environment 环境

  • Windows x64 Windows x64
  • Apache 2.4 Apache 2.4

Key Configuration in httpd.conf httpd.conf中的密钥配置

<Directory "${SRVROOT}/static">
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

# I have used FilterProvider as well an know this just does javascript at the moment
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript
SetOutputFilter DEFLATE

<IfModule alias_module>
    Alias "/static" "${SRVROOT}/static"
    ScriptAlias /cgi-bin/ "${SRVROOT}/cgi-bin/"
</IfModule>

With this configuration and a " static " folder under SRVROOT, I place a file bundle.js (3M of data). 使用此配置和SRVROOT下的“ 静态 ”文件夹,我放置一个文件bundle.js (3M数据)。 Polling this file at http://localhost/static/bundle.js gives me 600K of download with gzip compression. http://localhost/static/bundle.js查询此文件,可以通过gzip压缩下载600K。 ALL GOOD 都好

Now for the change. 现在换了。 The default path of the app needs to reverse proxy to another application and apache is just serving up static content. 应用程序的默认路径需要将代理转发到另一个应用程序,而apache只是提供静态内容。

<IfModule proxy_html_module>
    Include conf/extra/proxy-html.conf
</IfModule>

extra/proxy-html.conf file content extra / proxy-html.conf文件内容

#default proxy stuff above...
ProxyRequests off
ProxyPass / http://localhost:5000/
#ProxyPass /static/ /
ProxyHTMLURLMap http://localhost:5000/ /

<Location />
        ProxyPassReverse /
        ProxyHTMLEnable On
        ProxyHTMLURLMap  /      /
        RequestHeader    unset  Accept-Encoding
</Location>

<Location /static/ >
    ProxyPass !
</Location>

This still allows me to hit my static data, only now the gzip compression is not happening. 这仍然允许我点击我的静态数据,只是现在没有发生gzip压缩。 I do not know if this is a bug in apache or if there is a better way to configure this. 我不知道这是否是apache中的错误,或者是否有更好的方法来配置它。

Here are my requirements: 这是我的要求:

  • I cannot change the pathing of the url (static is where it is, and root url content gets reverse proxied 我无法更改url的路径(静态就是这样,root url内容被反向代理
  • I need compression 我需要压缩
  • Deployment is to a root folder that honestly is not named static , so the fact that I route (in this example) static to {some directory}/static it is really http://localhost/static/ * to a dist folder in all actuality. 部署是一个真正没有命名为静态的根文件夹,所以我将路由(在这个例子中) 静态{some directory} / static它实际上是http:// localhost / static / *到一个dist文件夹现实。

It appears that RequestHeader unset Accept-Encoding is bleeding over into the other Location definition. 似乎RequestHeader取消设置Accept-Encoding正在流入另一个Location定义。 This seems like it should not be expected behavior. 这似乎应该是预期的行为。 There appears to be two solutions to the problem. 这个问题似乎有两个解决方案。

  1. Remove the ProxyHTMLURLMap and RequestHeader unset Accept-Encoding as this needs to uncompress the content to do the url rewriting. 删除ProxyHTMLURLMapRequestHeader取消设置Accept-Encoding,因为这需要解压缩内容以进行URL重写。
  2. Inflate and Deflate the content. 膨胀和收缩内容。 I have yet to determine of this will inflate and deflate the static content on the server. 我还没有确定这会膨胀和缩小服务器上的静态内容。 The only reason I mention this is because the usetting of the Accept-Encoding seemed to bleed over into the static section. 我提到这个的唯一原因是因为Accept-Encoding的使用似乎渗透到静态部分。 -- Not sure how to test this yet. - 不知道如何测试这个。

Example of removing ProxyURLMap 删除ProxyURLMap的示例

ProxyRequests off
ProxyPass / http://localhost:5000/
ProxyPassReverse / http://localhost:5000/

<Location /static/ >
    ProxyPass !
</Location>

#Do not use this anymore
#<Location />
#        ProxyPassReverse /
#        ProxyHTMLEnable On
#        ProxyHTMLURLMap  /      /
#        RequestHeader    unset  Accept-Encoding
#</Location>

Example of using the INFLATE;DEFLATE 使用INFLATE; DEFLATE的示例

ProxyRequests off
ProxyPass / http://localhost:5000/
ProxyPassReverse / http://localhost:5000/

<Location />
        ProxyPassReverse /
        ProxyHTMLEnable On
        ProxyHTMLURLMap  /      /
        SetOutputFilter INFLATE;DEFLATE
</Location>

<Location /static/ >
    ProxyPass !
</Location>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM