How To Use Apache HTTP Server As Reverse Proxy
How To Use Apache HTTP Server As Reverse Proxy
How To Use Apache HTTP Server As Reverse Proxy
As Reverse-Proxy Using
mod_proxy Extension
TAGGED IN: UBUNTU , APACHE , MISCELLANEOUS
Introduction
Apache is a tried and tested HTTP server which comes with access to
a very wide range of powerful extensions. Although it might not seem
like the go-to choice in terms of running a reverse-proxy, system
administrators who already depend on Apache for the available rich
feature-set can also use it as a gateway to their application servers. In
most cases, this will translate to removing an additional layer from
their server set up or the need to use yet another tool just to redirect
connections.
In this DigitalOcean article, we are going to see set up Apache on
Ubuntu 13 and use it as a reverse-proxy to welcome incoming
connections and redirect them to application server(s) running on the
same network. For this purpose, we are going to use and work with
the mod_proxy extension and several other related Apache modules.
Glossary
1. Apache
2. Apache Working As A Reverse-Proxy Using mod_proxy
3. Installing Apache And mod_proxy
1.
2.
3.
5.
Restarting Apache
Apache
Apache HTTP server does not require an introduction, since it is
probably the most famous and popular web-server that exists. It is
possible to run Apache very easily on many different platforms and set
ups. The application comes with a lot of third party modules to handle
different kind of tasks (modrewrite for rule-based URL rewriting) and
one of them, albeit nowadays relatively neglected, is *modproxy*: The
Apache Module to implement a proxy (or gateway) for servers running
on the back-end.
Tip: According to some articles, Apache's name comes from server's
"patchy" nature - i.e. it being a collection of application patches
(or modules).
Note: To learn more about Apache, you can check out the Wikipedia
entry on the subject - Apache HTTP Server.
modproxyftp: This module does the same but for FTP protocol.
Note: To learn more about Apache and mod_proxy, you can check out
the official Apache documentation on the subject here.
Once you are prompted with the choice of modules you desire, you
can pass the below line listing the module names:
The list of modules:
proxy proxy_ajp proxy_http rewrite deflate headers proxy_balancer
proxy_connect proxy_html
proxy
proxy_http
proxy_ajp
rewrite
deflate
headers
proxy_balancer
proxy_connect
proxy_html
ProxyPass / http://0.0.0.0:8080/
ProxyPassReverse / http://0.0.0.0:8080/
ServerName localhost
</VirtualHost>
Enabling Load-Balancing
If you have multiple back-end servers, a good way to distribute the
connection when proxying them is to use Apache's load balancing
features.
Start editing the virtual-host settings like the previous step, but this
time using the below configuration example:
<Proxy balancer://mycluster>
# Define back-end servers:
# Server 1
BalancerMember http://0.0.0.0:8080/
# Server 2
BalancerMember http://0.0.0.0:8081/
</Proxy>
<VirtualHost *:*>
# Apply VH settings as desired
# However, configure ProxyPass argument to
# use "mycluster" to balance the load
ProxyPass / balancer://mycluster
</VirtualHost>
NameVirtualHost *:443
<VirtualHost *:443>
SSLEngine On
# Set the path to SSL certificate
# Usage: SSLCertificateFile /path/to/cert.pem
SSLCertificateFile /etc/apache2/ssl/file.pem
# Servers to proxy the connection, or;
# List of application servers:
# Usage:
# ProxyPass / http://[IP Addr.]:[port]/
# ProxyPassReverse / http://[IP Addr.]:[port]/
# Example:
ProxyPass / http://0.0.0.0:8080/
ProxyPassReverse / http://0.0.0.0:8080/
# Or, balance the load:
# ProxyPass / balancer://balancer_cluster_name
</VirtualHost>
Restarting Apache
Once you are happy with your configuration, you will need to restart
the cloud server for the changes to go into effect.
Execute the following command to restart Apache:
service apache2 restart