Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache ProxyPass error

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?

like image 274
Luiz Avatar asked Sep 04 '17 01:09

Luiz


People also ask

What is ProxyPass in Apache?

ProxyPass is the main proxy configuration directive. In this case, it specifies that everything under the root URL ( / ) should be mapped to the backend server at the given address.

Does Apache support reverse proxy?

In addition to being a "basic" web server, and providing static and dynamic content to end-users, Apache httpd (as well as most other web servers) can also act as a reverse proxy server, also-known-as a "gateway" server.

What is proxy timeout in Apache?

Apache has a default timeout of 60 seconds, you can increase it by creating a custom template in cwp.


1 Answers

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".

like image 194
larsks Avatar answered Oct 20 '22 13:10

larsks