How to setup Apache Reverse Proxy

A reverse proxy is a server that sits in front of web servers and forwards client requests to the appropriate server. Here are the steps to set up a reverse proxy using the Apache web server on Ubuntu 22.04:

  1. Install Apache: First, you need to install Apache on your server with the following command:
sudo apt update
sudo apt install apache2
  1. Enable the required modules: Next, you need to enable the required Apache modules with the following commands:
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod proxy_balancer
sudo a2enmod lbmethod_byrequests
  1. Configure the reverse proxy: Create a new configuration file for the reverse proxy with the following command:
sudo nano /etc/apache2/sites-available/proxy.conf

Add the following content to the file:

<VirtualHost *:80>

    ProxyPass / http://localhost:8080/
    ProxyPassReverse / http://localhost:8080/

Replace with the domain name of your website. Replace http://localhost:8080/ with the URL of the server you want to forward requests to.

  1. Enable the reverse proxy: Enable the reverse proxy configuration with the following command:
sudo a2ensite proxy.conf
  1. Restart Apache: Restart Apache to apply the changes with the following command:
sudo systemctl restart apache2

That’s it! You have set up a reverse proxy using the Apache web server. All requests to will be forwarded to the server at http://localhost:8080/. You can add additional ProxyPass and ProxyPassReverse directives to forward requests to other servers or URLs.