Apache Reverse Proxy Setup
The Apache web server can be used not only to serve static content, but also as a reverse proxy.
Thanks to this structure, Apache directs incoming HTTP requests to backend servers**.
Reverse proxy architecture is especially preferred in the following cases:
- Protecting backend applications from external access
- Distributing traffic to multiple servers (load balancing)
- Centrally manage SSL, cache and compression operations
- Acting as a gateway in microservice architectures
In this guide, you will learn reverse proxy setup and load balancing configuration using mod_proxy on Apache.
What You Will Learn in This Guide
- Apache enable mod_proxy module
- Creating reverse proxy configuration
- Setting up backend test servers (with Flask)
- Load balancing to multiple servers
- Difference between ProxyPass and ProxyPassReverse
- Common errors in reverse proxy configurations
How Does Apache Reverse Proxy Work?
In reverse proxy architecture, the client does not connect directly to backend servers.
The flow happens like this:
Client → Apache Reverse Proxy → Backend Sunucu
Apache receives the incoming request and forwards it to the specified backend address.
The backend response is sent back to the client via Apache.
Thanks to this method:
- Backend IP addresses are hidden
- Traffic is controlled from a central point
- Server load can be balanced
1. Enabling Required Apache Modules
The following Apache modules are required for reverse proxy configuration:
- mod_proxy → Basic proxy engine
- mod_proxy_http → HTTP request forwarding
- mod_proxy_balancer → Load balancing system
- mod_lbmethod_byrequests → Round-robin distribution algorithm
To enable modules:
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod proxy_balancer
sudo a2enmod lbmethod_byrequests
Restart Apache for the module changes to take effect:
sudo systemctl restart apache2
2. Creating Backend Test Servers (Optional)
You can create two simple backend applications to test the reverse proxy configuration.
Flask Setup
sudo apt update
sudo apt install python3-pip
sudo pip3 install Flask==1.1.4
Backend Sunucu 1 (Port 8080)
Create file:
nano ~/backend1.py
Content:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def home():
return 'Hello world!'
Backend Sunucu 2 (Port 8081)
Copy the file:
cp ~/backend1.py ~/backend2.py
nano ~/backend2.py
Change the response message:
return 'Howdy world!'
Backend Sunucuları Başlatma
FLASK_APP=~/backend1.py flask run --port=8080 >/dev/null 2>&1 &
FLASK_APP=~/backend2.py flask run --port=8081 >/dev/null 2>&1 &
Test that the servers are running:
curl http://127.0.0.1:8080/
curl http://127.0.0.1:8081/
3. Apache Reverse Proxy Configuration
Edit the Apache VirtualHost file:
sudo nano /etc/apache2/sites-available/000-default.conf
Tek Backend Sunucuya Reverse Proxy
Add the following configuration in VirtualHost:
<VirtualHost *:80>
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:8080/
ProxyPassReverse / http://127.0.0.1:8080/
</VirtualHost>
Remarks
ProxyPreserveHost
It transmits the host header from the client to the backend.
ProxyPass
It directs the incoming request to the backend server.
ProxyPassReverse
Edits the redirect URLs in the backend response.
Restart Apache:
sudo systemctl restart apache2
When you enter the server IP address from the browser, you should see the backend output.
http://sunucu_ip
4. Apache Load Balancing Configuration
If you have more than one backend server, you can load balance via Apache.
Edit the VirtualHost configuration as follows:
<VirtualHost *:80>
<Proxy balancer://mycluster>
BalancerMember http://127.0.0.1:8080
BalancerMember http://127.0.0.1:8081
</Proxy>
ProxyPreserveHost On
ProxyPass / balancer://mycluster/
ProxyPassReverse / balancer://mycluster/
</VirtualHost>
In this configuration, Apache sends requests to backend servers sequentially using the round-robin algorithm.
Example flow:
İstek 1 → 8080
İstek 2 → 8081
İstek 3 → 8080
As you refresh the browser, you may see different backend responses.
Frequently Asked Questions
What does reverse proxy do?
Reverse proxy hides backend servers and redirects traffic from the client. It also provides central management of SSL, cache and security operations.
What is the difference between ProxyPass and ProxyPassReverse?
ProxyPass
It directs the request from the client to the backend server.
ProxyPassReverse
It organizes the redirect URLs returned by the backend in accordance with the client.
What protocols does
mod_proxysupport?
Apache mod_proxy can work with the following protocols:
HTTP (mod_proxy_http)
WebSocket (mod_proxy_wstunnel)
AJP (mod_proxy_ajp)
FTP (mod_proxy_ftp)
How can I stop backend servers?
To shut down Flask test servers:
killall flask
Result
In this guide, you have installed reverse proxy and load balancing on Apache using mod_proxy.
Thanks to this structure:
You have hidden your backend applications You have distributed traffic to multiple servers You have established a scalable web architecture
Thanks to Apache's modular structure, you can create a powerful reverse proxy solution for Python, Node.js, PHP, Ruby and other application servers.

