Apache ProxyPass error

7.4k views Asked by At

I have to redirect all apache requests on 80 to tomcat on 8080, except one path.

So, if a receive http://example.com/anything --> tomcat:8080.

But, if the url is that: http://example.com/site --> apache should serve and no redirect is needed.

Currently, there is a folder named site inside /var/www/html/.

This is my current configuration file:

site.conf (this file contains only the following and is inside the conf.d folder)

<LocationMatch "/*">
        Allow from all
        ProxyPass               /site !  
        ProxyPass               http://127.0.0.1:8080
        ProxyPassReverse        http://127.0.0.1:8080
</LocationMatch>

I think this is a simple thing to accomplish with apache, but I have tried everything that I could find and I am still getting the error:

ProxyPass|ProxyPassMatch can not have a path when defined in a location.

The thing is that the root website is running on tomcat, but the other runs on apache (the one that I called site in this question).

If anyone can help, I appreciate.

Thanks!

Update 1 - 09/06/2017

I get it to work if I remove the LocationMatch and put the ProxyPass direct in the .conf file:

ProxyPass               /site !
ProxyPassReverse        /site !
ProxyPass               / http://127.0.0.1:8080
ProxyPassReverse        / http://127.0.0.1:8080

But, I would like to know, why is that? What is the impact of putting this directives outside the LocationMatch tag? And, most important, why I cannot accomplish the same result using the LocationMatch?

1

There are 1 answers

2
larsks On BEST ANSWER

I think the error is pretty clear:

ProxyPass|ProxyPassMatch can not have a path when defined in a location.

According to the documentation, inside a context block like Location or LocationBlock the ProxyPass directive does not accept a path:

When used inside a <Location> section, the first argument is omitted and the local directory is obtained from the <Location>. The same will occur inside a <LocationMatch> section; however, ProxyPass does not interpret the regexp as such, so it is necessary to use ProxyPassMatch in this situation instead.

You're getting the error because you were trying to use a path:

ProxyPass               /site !  

You could try to resolve this in theory by using multiple <Location> sections, like this:

<Location />
    ProxyPass http://backend/
</Location>

<Location /site>
    ProxyPass !
</Location>

The ordering of these sections is important.

Your solution of using ProxyPass directives outside of a LocationMatch block is probably the simplest solution.


As a side note, your LocationMatch directive is incorrect. The argument to LocationMatch is a regular expression, and /* would only match URLs consisting only of / characters. That is, it would match / or // or /////////, etc. I think you really meant /.*. The * in a regular expression means "the previous character, zero or more times".