Apache ProxyPass ignore static files

You need to use the ProxyPass ! argument with a path, not in a <Location> block, for example:

ProxyPass /static !
ProxyPass / http://localhost:8081/
ProxyPassReverse / http://localhost:8081/

I believe these rules are processed in the order they appear in the config, so be sure to specify exclude rules first.


The way to make it work inside Location blocks is to reverse the order, i.e. have the most specific Location statement last:

DocumentRoot /path/to/foo
  ServerName foo.com
  ServerAdmin [email protected]

  RewriteEngine On

  <Directory /path/to/foo>
    AllowOverride  None
    Require all granted
  </Directory>

  ProxyRequests Off
  ProxyVia Off
  ProxyPreserveHost On

  <Proxy *>
    AddDefaultCharset off
    Order deny,allow
    Allow from all
  </Proxy>

  <Location />
    ProxyPass           http://localhost:8081/
    ProxyPassReverse    http://localhost:8081/
    SetEnv              proxy-sendchunks 1
  </Location>

  # don't pass through requests for statics (image,js,css, etc.)
  <Location /static/>
    ProxyPass !
  </Location>

This works. See https://httpd.apache.org/docs/2.4/mod/mod_proxy.html#proxypass for more details - it contains an example pretty much exactly as the above.