Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to perform proxypassreverse with regex

I am stuck in this problem for past few days, I am using reverse proxy of Apache server and I managed to run the reverse proxy by making the following changes in config file:

ProxyPass: /server-01/ server-01.{My server}
ProxyPassReverse: /server-01/ server-01.{My server}

ProxyPass: /server-02/ server-02.{My server}
ProxyPassReverse: /server-02/ server-02.{My server}

ProxyPass: /server-03/ server-03.{My server}
ProxyPassReverse: /server-03/ server-03.{My server}

ProxyPass: /server-04/ server-04.{My server}
ProxyPassReverse: /server-04/ server-04.{My server}

All this is working but I want to make this dynamic so that I dont have to add new code and restart Apache when a new proxy server is added!

like image 338
MKAfridi Avatar asked Mar 16 '23 22:03

MKAfridi


1 Answers

In order to use a regex you must use ProxyPassMatch:

ProxyPassMatch ^/server-(\d+)/$ server-$1.{My server}

The purpose of ProxyPassReverse is to fix any Location headers that the proxy server issues for itself. For example if I proxy mywebsite.com to bluewebsite.com and bluewebsite.com issues a redirect to bluewebsite.com/1, ProxyPassReverse will intercept it and redirect me to mywebsite.com/1 instead.

If your proxy server issues redirects to the proper front-end URLs (or does not use redirects) then ProxyPassReverse is not needed. If you do need it, you are out of luck in this example because it does not accept regexes.

Here is another question that might help you: ProxyPassMatch with ProxyPassReverse

like image 97
Dondi Michael Stroma Avatar answered Mar 24 '23 12:03

Dondi Michael Stroma