Apache ProxyPass Error

I need to redirect all apache requests to 80 to tomcat to 8080, except for one path.

So, if you get http://example.com/anything -> tomcat: 8080.

But, if the url is this: http://example.com/site → apache should serve and no redirect is required.

There is currently a folder called site inside /var/www/html/ .

This is my current configuration file:

site.conf (this file contains only the following and is located 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 case with apache, but I tried everything I could find and I still get the error:

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

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

If anyone can help, I appreciate.

Thanks!

Update 1 - 06/09/2017

I earned it if I remove LocationMatch and put ProxyPass directly 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 this is so? What is the effect of placing these directives outside the LocationMatch tag? And, most importantly, why can't I accomplish the same result using LocationMatch ?

+5
source share
1 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 such as Location or LocationBlock ProxyPass directive ProxyPass not take a path

When used within the <Location> section, the first argument is omitted, and the local directory is obtained from <Location> . The same thing will happen inside the <LocationMatch> section; however, ProxyPass does not interpret the regular expression as such, so in this situation you must use ProxyPassMatch.

You get an error because you are trying to use the path:

 ProxyPass /site ! 

You can try to resolve this theoretically using several <Location> sections, for example:

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

The order of these sections is important .

Your decision to use ProxyPass directives outside the LocationMatch block is probably the easiest solution.


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

+4
source

Source: https://habr.com/ru/post/1271485/


All Articles