[英]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 环境
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: 这是我的要求:
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.
这个问题似乎有两个解决方案。
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.