How to use Apache Reverse Proxy Server to service to multiple web server?

Hello,
I installed and configure an Apache Web Server as a Reverse Proxy on CentOS 8. I created a Virtual Host file (reverse_proxy.conf) under the “/etc/httpd/conf.d” directory with below content:

<VirtualHost *:80>
        ProxyPreserveHost On
        ProxyPass / http://192.168.1.20/
        ProxyPassReverse / http://192.168.1.20/
</VirtualHost>

It’s worked.
I want this Reverse Proxy Server service to more than websites:

The Internet ---> Apache Reverse Proxy ---> Web Server 1
                                       ---> Web Server 2

I have a question. For each website I need a Virtual Host config file or I can put all websites configuration in one virtual Host file?

I created another Virtual Host config file for other websites:

The content of reverse_proxy1.conf file is:

<VirtualHost *:80>
        ServerName Website1
        ProxyPreserveHost On
        ProxyPass / http://192.168.1.20/
        ProxyPassReverse / http://192.168.1.20/
</VirtualHost>

The content of reverse_proxy2.conf file is:

<VirtualHost *:80>
        ServerName Website2   
        ProxyPreserveHost On
        ProxyPass / http://192.168.1.4/
        ProxyPassReverse / http://192.168.1.4/
</VirtualHost>

But when I browse my Reverse Proxy Server then it can’t handle the requests and show me below error:

I checked log file and it show me:

# cat /var/log/httpd/error_log
[Wed Mar 17 01:12:44.817647 2021] [proxy:error] [pid 28599:tid 28649] (113)No route to host: AH00957: HTTP: attempt to connect to 192.168.1.20:80 (192.168.1.20) failed
[Wed Mar 17 01:12:44.817775 2021] [proxy_http:error] [pid 28599:tid 28649] [client 10.0.3.2:52142] AH01114: HTTP: failed to make connection to backend: 192.168.1.20

Why it just see “reverse_proxy1.conf” file?

Thank you.

I want to clear my question more:
I don’t need a load balance. Please consider below diagram:

The Internet ---> Apache Reverse Proxy ---> Apache Web Server 1 (IP: 1.2.3.4, Name: Yahoo.com)
                                       ---> Apache Web Server 2 (IP: 1.2.3.5, Name: Google.com)

Yahoo.com and Google.com are example.

I want my Reverse Proxy service to these web servers. Each servers has a different domain name and IP address. My Yahoo.com server maybe turned off or…but I want my Apache Reverse Proxy service to Google.com server.

1_v4Pp0pG5WMbknprejifVmw

I crated a .conf file with below content:

<VirtualHost *:80>
     ServerName node3
     ErrorLog /var/log/httpd/error_log
     TransferLog /var/log/httpd/access_log
     <Location />
         ProxyPass  http://192.168.1.4/ 
         ProxyPassReverse   http://192.168.1.4/
     </Location>
   </VirtualHost>


    <VirtualHost *:80>
     ServerName node4
     ErrorLog /var/log/httpd/error_log
     TransferLog /var/log/httpd/access_log
     <Location />
         ProxyPass  http://192.168.1.20/ 
         ProxyPassReverse   http://192.168.1.20/
     </Location>
   </VirtualHost>

But I got a same result!!
I want to have one Reverse Proxy server that service to some web servers that each of them has theirs domains and IPs.
I want to know, for 10 different websites that each of them has different IPs and domain names, I need 10 Reverse Proxy servers?

Yes. How else is the server supposed to know what traffic to route where?

As an aside, from my experience NGiNX is better at this than Apache. You might want to check that out.
You’d still to configure all hosts separately, but you get nice options like HTTP keepalive between the proxy and the servers, caching, etc, in a very readable format. Plus performance is better.

1 Like

Thank you.
Thus it will true for the ModSecurity too?

What do you want to achieve with mod_security?

1 Like

Protect some servers from attacks. When ModSecurity need Apache then my Reverse Proxy must Apache too and…

yes, that seems to be available for NGiNX too: https://docs.nginx.com/nginx-waf/

Thanks for sharing this link, it’s useful. And I agree with you that NgiNX is much better than Apache in this case. However, it was hard for me to create proxies via both apps. Don’t know why but every time it’s a kind of error when I try to configure a reverse proxy server for multiple web server.

Maybe the codes I usually use are wrong, but I’ve been always following guides from Github. I read on proxies.com that you can’t simply configure proxies on some of the old Apache versions. Strange…

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.