Beginner Fundamentals
Reverse Proxy with mod_proxy
A reverse proxy receives requests and forwards them to another server, then returns the response. Apache does this with the mod_proxy module, commonly used to sit in front of application servers.
Enable the Modules
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo systemctl restart apache2
Basic Forwarding
ProxyPass sends matching requests to a backend; ProxyPassReverse fixes the headers in the response:
<VirtualHost *:80>
ServerName app.example.com
ProxyPass / http://127.0.0.1:3000/
ProxyPassReverse / http://127.0.0.1:3000/
</VirtualHost>
Here a Node or other app runs on port 3000, and Apache exposes it on port 80.
Proxy Only One Path
ProxyPass /api http://127.0.0.1:5000/
ProxyPassReverse /api http://127.0.0.1:5000/
Requests to /api go to the backend, while the rest is served by Apache directly.
Apply Changes
sudo apache2ctl configtest
sudo systemctl reload apache2
A reverse proxy lets Apache handle HTTPS, caching, and routing while your application focuses on its own logic.