Apache2 : Configure mod_proxy2024/05/31 |
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>
a2enconf revers_proxy Enabling conf revers_proxy. To activate the new configuration, you need to run: systemctl reload apache2root@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 apache2root@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>
a2enconf revers_proxy Enabling conf revers_proxy. To activate the new configuration, you need to run: systemctl reload apache2root@www:~# a2enmod proxy proxy_http proxy_balancer lbmethod_byrequests Module proxy already enabled Considering dependency proxy for proxy_http: Module proxy already enabled Module proxy_http already enabled 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: Enabling module slotmem_shm. Enabling module proxy_balancer. 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 apache2root@www:~# systemctl restart apache2 |
[4] | Access to frontend server to verify backend servers response like follows. |
Sponsored Link |