9

Having an issue with Apache front server connecting to a Jetty application server.

I thought that ProxyPass ! in a location block was supposed to NOT pass on processing to the application server, but for some reason that is not happening in my case, Jetty shows a 404 on the missing statics (js, css, etc.)

Here's my Apache (v 2.4, BTW) virtual host block:

DocumentRoot /path/to/foo
  ServerName foo.com
  ServerAdmin webmaster@foo.com

  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>

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

  <Location />
    ProxyPass           http://localhost:8081/
    ProxyPassReverse    http://localhost:8081/
    SetEnv              proxy-sendchunks 1
  </Location>
user9517
  • 114,104
  • 20
  • 206
  • 289
virtualeyes
  • 665
  • 3
  • 10
  • 28

2 Answers2

13

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.

Kyle Smith
  • 9,563
  • 1
  • 30
  • 32
  • I need to check this, but Apache 2.4 docs indicate that ProxyPass is the preferred/performant approach to proxying. I tried, BTW, ProxyPass /static ! outside of Location block and same deal, Jetty tries to serve it – virtualeyes Apr 15 '12 at 16:35
  • 1
    +1, you are, however, correct in that breaking all the proxy rules outside of Location blocks does the trick ;-) Now, I would like to get this working in Location blocks since the I recall the 2.4 docs saying this is the way to do it now for max performance... – virtualeyes Apr 15 '12 at 16:38
  • 1
    ok, in 2.4 docs they state that multiple proxy directives outside a location block can be a performance bottleneck; however, given that I'll have a handful at most, a non-issue. Location blocks would work, BTW, if I had a more specific directive than for the catch all. Appears that after is processed, it moves on to and proxies the /static/foo/bar.css file to Jetty, ignoring the first directive... – virtualeyes Apr 15 '12 at 17:17
  • So is this possible in Apache 2.4.10 using Location blocks? – fideloper Aug 19 '14 at 19:18
1

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 webmaster@foo.com

  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.

Karalga
  • 111
  • 2