Support Online
Skip to main content

Apache Reverse Proxy Setup

In this guide, you will learn how to configure Reverse Proxy on the Apache web server.

Thanks to Apache's mod_proxy module, you can direct incoming HTTP(S) requests to back-end application servers.

Using reverse proxy is especially preferred in the following cases:

  • Hide backend servers
  • Distribute traffic across multiple servers
  • Centralizing SSL management
  • Increase performance

What Will You Learn in This Guide?

This guide covers the following topics step by step:

  • Apache enable mod_proxy modules
  • Installing a reverse proxy on a single backend server
  • Load balancing configuration
  • Creating test backend servers (Flask)
  • ProxyPass and ProxyPassReverse logic

1. Enabling Apache mod_proxy Modules

To use reverse proxy, some Apache modules must be active.

Required modules:

  • mod_proxy
  • mod_proxy_http
  • mod_proxy_balancer
  • mod_lbmethod_byrequests

To enable modules:

sudo a2enmod proxy proxy_http proxy_balancer lbmethod_byrequests

Restart Apache:

sudo systemctl restart apache2

2. Creating Test Backend Servers (Optional)

You can use a small Flask application to test the reverse proxy configuration.

Install the necessary packages:

sudo apt update
sudo apt install python3-pip
sudo pip3 install flask

Creating backend 1:

nano ~/backend1.py
from flask import Flask

app = Flask(__name__)

@app.route("/")
def home():
return "Backend Sunucu 1"

if __name__ == "__main__":
app.run(port=8080)

Creating backend 2:

cp ~/backend1.py ~/backend2.py
nano ~/backend2.py

Change the message:

return "Backend Sunucu 2"
Backend sunucularını başlatma
FLASK_APP=~/backend1.py flask run --port=8080 &
FLASK_APP=~/backend2.py flask run --port=8081 &

3. Apache Reverse Proxy Configuration

We will configure Apache via VirtualHost.

Open the VirtualHost file:

sudo nano /etc/apache2/sites-available/000-default.conf

Reverse Proxy to Single Backend Server:

<VirtualHost *:80>

ProxyPreserveHost On

ProxyPass / http://127.0.0.1:8080/
ProxyPassReverse / http://127.0.0.1:8080/

</VirtualHost>

Restart Apache

sudo systemctl restart apache2

Now all incoming HTTP requests are directed to the backend server on port 8080.

Load Balancing Configuration

You can load balance by using more than one backend server.

Load Balancer configuration:

<VirtualHost *:80>

<Proxy "balancer://uygulama_havuzu">

BalancerMember http://127.0.0.1:8080
BalancerMember http://127.0.0.1:8081

</Proxy>

ProxyPreserveHost On

ProxyPass / balancer://uygulama_havuzu/
ProxyPassReverse / balancer://uygulama_havuzu/

</VirtualHost>

Restart Apache:

sudo systemctl restart apache2

Each time you refresh the page, Apache will redirect the request to different backend servers.

Frequently Asked Questions

What is the difference between reverse proxy and forward proxy?

Forward Proxy → hides the client Reverse Proxy → hides the backend servers

Why use reverse proxy?

Main advantages:

Security Load balancing SSL offloading Central traffic management Performance increase

Can I use HTTPS backend?

Yes. All you have to do is use https:// in ProxyPass.

Example:

ProxyPass / https://127.0.0.1:8443/

How many backend servers can I add?

Apache can theoretically manage a large number of backend servers. In practice, this number depends on system resources.

Result

With this guide:

You have enabled the Apache mod_proxy module You have learned the reverse proxy configuration You have installed load balancing

This architecture specifically:

Node.js applications Python (Flask / Django) Java services Microservice architectures

It is a very powerful solution for.

You can easily implement this configuration on your GenixNode servers.