How to use Apache as a Reverse Proxy ?
Learning
How Apache Modules work
How to enable modules
How to use apache with single backend server
How to use apache with multiple backend server
: In my production environment i was having one apache server with one apache tomcat server running java application so there i was facing some issue such as Bad request, so to demestify that i am learning apache and its modules.
Apache
Apache is a web server and apache tomcat is a application server
- While using apache as a reverse proxy means all the traffic will come to apache server first and then that traffic will be redirected to the apache tomcat server.
Apache as reverse proxy allows, load balancing, Caching, Compression, SSL Encryption
When we installl apache it has the modules but we need to enable the modules
How to enable modules
sudo a2enmod proxy
- then restart the apache server
How to use apache with single backend server
- this is the conf file inside apache
- there is a server running in the backend with address 127.0.0.1:8080/
<VirtualHost *:80>
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:8080/
ProxyPassReverse / http://127.0.0.1:8080/
</VirtualHost>
How to use apache with multiple backend server
<VirtualHost *:80>
<Proxy balancer://mycluster>
BalancerMember http://127.0.0.1:8080
BalancerMember http://127.0.0.1:8081
</Proxy>
ProxyPreserveHost On
ProxyPass / balancer://mycluster/
ProxyPassReverse / balancer://mycluster/
</VirtualHost>