简体   繁体   中英

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. I can get this to gzip compress just fine. However, when I add proxy to other paths and add an exception for my static data, compression stops.

Environment

  • Windows x64
  • Apache 2.4

Key Configuration in 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). Polling this file at http://localhost/static/bundle.js gives me 600K of download with gzip compression. 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.

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

extra/proxy-html.conf file content

#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. I do not know if this is a bug in apache or if there is a better way to configure this.

Here are my requirements:

  • I cannot change the pathing of the url (static is where it is, and root url content gets reverse proxied
  • 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.

It appears that RequestHeader unset Accept-Encoding is bleeding over into the other Location definition. 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.
  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. -- Not sure how to test this yet.

Example of removing 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

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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