You are here
Home > Web Hosting > Apache > mod_proxy Installation and Configuration on Apache

mod_proxy Installation and Configuration on Apache

mod_proxy installation on Apache

Introduction

mod_proxy is a proxy/gateway for the Apache server. It allows you to direct Apache requests to other sites and/or ports within the web server. It can also support load balancing algorithms as well. This guide assumes you already have Apache 2.2 installed from source to build the modules.  To read more about it you can review the module documentation on Apache’s mod_proxy page

Install mod_proxy

Go to the source directory of the Apache installation

cd /usr/src/httpd-2.2.24

Replace the path with where you downloaded the Apache installation.

Reconfigure the existing apache configuring appending the mod_proxy lines

./config-nice --enable-proxy=shared

Rebuild Apache:

make

Install the new Apache

make install

Once you have done that you will want to edit the Apache Configuration to load the modules

vim /etc/httpd/conf/httpd.conf

Add the following modules and save the file

LoadModule proxy_module lib/apache/mod_proxy.so
LoadModule proxy_http_module lib/apache/mod_proxy_http.so
LoadModule proxy_balancer_module lib/apache/mod_proxy_balancer.so
LoadModule proxy_connect_module lib/apache/mod_proxy_connect.so
LoadModule proxy_ftp_module lib/apache/mod_proxy_ftp.so
LoadModule proxy_scgi_module lib/apache/mod_proxy_scgi.so
LoadModule proxy_ajp_module lib/apache/mod_proxy_ajp.so

Restart Apache to load them

service httpd restart

Configure mod_proxy

Once mod_proxy is loaded you can now configure it to work on domains.

Reverse Proxy Configuration:

<VirtualHost 192.168.1.10:80>
ServerName  domain.com
ProxyPreserveHost On
 ProxyPass / http://127.0.0.1:8080/
 ProxyPassReverse / http://127.0.0.1:8080/
</VirtualHost>

This example will pass requests to the same server on port :8080. You could utilize this to pass requests do a different application, java, ruby, tomcat etc.

SSL Reverse Proxy Configuration:

<VirtualHost 192.168.1.10:443>
ServerName  domain.com
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:8080/
ProxyPassReverse / http://127.0.0.1:8080/
SSLCertificateFile /path/to/certificate.crt
SSLCertificateKeyFile /path/to/certificate.key
SSLCertificateChainFile /path/to/chainfile.crt
</VirtualHost>

This configuration is almost identical except you are setting the variables for SSL Configuration.

Load Balancing Proxy Configuration:

This allows you to utilize multiple back-end servers with a single Apache front-end load balancing the requests.

<Proxy balancer://cluster>
BalancerMember http://192.168.1.10:8080/
BalancerMember http://192.168.1.11:8080/
</Proxy>

<VirtualHost 192.168.1.10:80>
ServerName  domain.com
ProxyPass / balancer://cluster
</VirtualHost>

You would add in the IP addresses for each of the members to be load balanced  as BalancerMember.

Once you have added the new configurations, you go ahead and restart apache again to load in the new mod_proxy settings

service httpd restart

Leave a Reply

avatar
  Subscribe  
Notify of
Top