Apache Reverse Proxy allows you to run one or more back-end servers behind a proxy server. Here’s how to configure Apache Reverse Proxy on Ubuntu/Debian system.
Apache Reverse Proxy allows all traffic and forwards it to run one or more backend servers or containers behind a proxy server, without exposing them publicly. The back-end web server can be either another Apache2 or open source HTTP server like Nginx. Apache2 HTTP server is one of the most popular open source web server that is being used today.
There are many reasons to install and configure a proxy server. For Example, reverse proxy can help you to add security, for load balancing, restrict access to certain locations in order to prevent attacks and many more. This article explains how to install and configure apache reverse proxy configuration step by step for HTTPS Server on Ubuntu/Debian:
- Installing Apache2
- Configure Apache2
- Enable its proxy modules
- Enable the SSL
- Restart Apache2
Step 1: Install Apache2
Installing Apache2 is very simple and easy to run. To do Installations, run the below commands simply:
After installing Apache2 on your system, use the following systemctl commands on Debian Linux or Ubuntu Linux version Ubuntu to stop, start, enable and restart Apache2 to always restart when the server boots up.
You can view web server status using the following command:
To check Apache2 setup, open your browser and browse to the server hostname or your system IP address and you should see Apache2 default test page as shown below. When you see that, then Apache2 is working as expected. http://localhost
Step 2: Configure Apache2 as Reverse Proxy
Apache2 is successfully installed and ready to use. You can now configure Apache2 to work as a apache2 reverse proxy ubuntu. Apache2 proxy module’s ProxyPass and ProxyPassReverse function provide a reverse proxy. To use ProxyPass and ProxyPassReverse, you must first know that where you want to direct site traffic.
The apache2 reverse proxy server will listen for all traffic on the default HTTP port, which is port 80 in a simple setup. The back-end server which host the website content will listen on a custom port and it is most likely port 8080.
In this blog article, we are going set up Apache2 to listen on port 80 and then direct traffic to the back-end server which listens on port 8080. Run below command to create a proxy VirtualHost file called Apache2Proxy.conf.
Then add the following block of codes in the Apache2Proxy.conf file and then save it.
Apache2Proxy.conf file contains your server name as well as the proxy_pass where traffic will be directed when received by the http proxy server.
Step 3: Enable Apache2 Proxy
Apache2 web server is now installed and setup successfully. Apache has many available bundled modules bundled with in it. These modules are not enabled in fresh apache2 installation. First we’ll need to enable the modules we need to enable required apache mod_proxy module and several of its add-on modules to support different network protocols. Run the below listed commands to enable its http proxy modules.
Now enable the VirtualHost site and restart Apache2 to enable reload the Apache2 modules configuration.
Launch a web browser of your choice and navigate to your server hostname like example.com. You will now be proxied to your Apache2 server on default port i.e 8080.
Step 4: Enable the SSL
If you want to enable the apache reverse proxy ssl module then run the below command to enable apache reverse proxy https proxy pass:
This will provide secure apache reverse proxy http to https support to backend servers.
Step 5: Restart Apache2
To make these changes into effect, restart Apache by running the below command:
Congratulations! You have successfully installed and configured Apache2 reverse proxy on your Linux system.
In this tutorial, we explored and discussed what is a Proxy Server and apache reverse proxy example configuration step by step. We also learned how to set up and configure apache2 as a reverse proxy on a linux system. In our upcoming tutorials, we’ll discuss more interesting topics about apache and other web server solution stacks.
You may also like the below more related articles: