Ubuntu 22.04
Sponsored Link

Apache2 : Configure mod_proxy2022/05/12

 
Enable [mod_proxy] module to configure reverse proxy settings.
This example is based on the environment like follows.
-----------+---------------------------+-----------
           |                           |
           |10.0.0.31                  |10.0.0.51
+----------+-----------+   +-----------+----------+
|   [ www.srv.world ]  |   | [ node01.srv.world ] |
|      Web Server#1    |   |      Web Server#2    |
+----------------------+   +----------------------+

[1] Configure Apache2.
root@www:~#
vi /etc/apache2/conf-available/revers_proxy.conf
# create new

<IfModule mod_proxy.c>
    ProxyRequests Off
    <Proxy *>
        Require all granted
    </Proxy>
    # backend server and forwarded path
    ProxyPass / http://node01.srv.world/
    ProxyPassReverse / http://node01.srv.world/
</IfModule> 

root@www:~#
a2enconf revers_proxy

Enabling conf revers_proxy.
To activate the new configuration, you need to run:
  systemctl reload apache2

root@www:~#
a2enmod proxy proxy_http

Module proxy already enabled
Considering dependency proxy for proxy_http:
Module proxy already enabled
Enabling module proxy_http.
To activate the new configuration, you need to run:
  systemctl restart apache2

root@www:~#
systemctl restart apache2

[2] Access to frontend server to verify backend server responses like follows.
[3]
It's possible to configure load balancing settings.
-----------+---------------------------+--------------------------+------------
           |                           |                          |
           |10.0.0.31                  |10.0.0.51                 |10.0.0.52
+----------+-----------+   +-----------+----------+   +-----------+----------+
|   [ www.srv.world ]  |   | [ node01.srv.world ] |   | [ node02.srv.world ] |
|      Web Server#1    |   |      Web Server#2    |   |      Web Server#3    |
+----------------------+   +----------------------+   +----------------------+

root@www:~#
vi /etc/apache2/conf-available/revers_proxy.conf
# create new

<IfModule mod_proxy.c>
    ProxyRequests Off
    <Proxy *>
        Require all granted
    </Proxy>
    # specify the way of load balancing with [lbmethod]
    # also possible to set [bytraffic] which means httpd balances requests by traffic
    ProxyPass / balancer://cluster lbmethod=byrequests
    <proxy balancer://cluster>
        BalancerMember http://node01.srv.world/ loadfactor=1
        BalancerMember http://node02.srv.world/ loadfactor=1
    </proxy>
</IfModule>

root@www:~#
a2enconf revers_proxy

Enabling conf revers_proxy.
To activate the new configuration, you need to run:
  systemctl reload apache2

root@www:~#
a2enmod proxy proxy_http proxy_balancer lbmethod_byrequests

Module proxy already enabled
Considering dependency proxy for proxy_http:
Module proxy already enabled
Enabling module proxy_http.
Considering dependency proxy for proxy_balancer:
Module proxy already enabled
Considering dependency alias for proxy_balancer:
Module alias already enabled
Considering dependency slotmem_shm for proxy_balancer:
Module slotmem_shm already enabled
Module proxy_balancer already enabled
Considering dependency proxy_balancer for lbmethod_byrequests:
Considering dependency proxy for proxy_balancer:
Module proxy already enabled
Considering dependency alias for proxy_balancer:
Module alias already enabled
Considering dependency slotmem_shm for proxy_balancer:
Module slotmem_shm already enabled
Module proxy_balancer already enabled
Enabling module lbmethod_byrequests.
To activate the new configuration, you need to run:
  systemctl restart apache2

root@www:~#
systemctl restart apache2

[4] Access to frontend server to verify backend servers response like follows.
Matched Content