OS: CentOS/RHEL
You guys must be wondering when Apache is used as Reverse proxy when it dominates > 60% of the Web Server space, but it acts as the best reverse proxy with the help of "mod_proxy" module
Configuration for Single Application Server
Step 1: Installing Apache
cmd # yum install httpd -y
Step 2: Edit Apache Configuration (Enable the mod_proxy module for make Apache to act as proxy)
# vi /etc/httpd/conf/httpd.conf
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_http_module modules/mod_proxy_http.so
Step 3: Edit Apache Configuration (Proxy configuration for the Application Port, proxy for single server)
# vi /etc/httpd/conf/httpd.conf
ProxyPreserveHost On
# ProxyPass / http://[IP Addr.]:[port]/
# ProxyPassReverse / http://[IP Addr.]:[port]/
# Example:
ProxyPass /myapp http://0.0.0.0:8080/myapp
ProxyPassReverse /myapp http://0.0.0.0:8080/myapp
# Thats it, done!, just restart the apache service and check the website being proxy'd through Apache
cmd # service httpd restart
Step 4: Edit Apache Configuration if you want the traffic to fall on the domain name itself instead of "/myapp" suffix
# vi /etc/httpd/conf/httpd.conf
Step 5: If you want the website served on the Base URL "www.theiot.in", the below configuration will make the page served on "www.theiot.in"
#vi /etc/httpd/conf/httpd.conf
RedirectMatch ^/$ http://www.theiot.in/myapp
# This will make the "myapp" page server when the end user enters "www.theiot.in" on their browser instead of "www.theiot.in"
==================================
Configuration for Multiple Application Servers (Apache as a Load Balancer)
Step 1: Edit the Apache configuration (Assuming two Application Servers)
# Server 1
BalancerMember http://0.0.0.0:8080/myapp
# Server 2
BalancerMember http://0.0.0.0:8081/myapp
ProxyPass /myapp balancer://mycluster
Step 2: Restart Apache Service
cms # service httpd restart
Done!, now check the URL and confirm the page is served.
Note:
cmd is the prefix for the commands to be executed in the terminal
This is a simple tutorial to help the IT admins out there, but still many configurations can be done using "mod_proxy" such a sticky sessions and so on, which will be covered in my future articles.
Please write to me if you like this post!
No comments:
Post a Comment