An Apache reverse proxy accepts requests from clients and forwards them to a backend application such as Node.js, Python or a Java server, then returns the answer. Enable proxy and proxy_http, then use ProxyPass and ProxyPassReverse inside a virtual host. The visitor only sees Apache, while the app listens privately on a local port.
A reverse proxy gives you TLS termination, one public entry point for many apps, and a place for caching, compression and access rules. This guide covers the setup, forwarded headers, WebSockets, load balancing and the settings that matter in production for an apache reverse proxy.
A forward proxy sits in front of clients and fetches sites for them. A reverse proxy sits in front of servers and receives requests on their behalf. In Apache, ProxyRequests Off keeps forward proxying disabled, and that must stay off: an open forward proxy is abused quickly.
For WebSockets add proxy_wstunnel; for load balancing add proxy_balancer and lbmethod_byrequests.
What each line does:
ProxyPass maps the public path to the backend URL.ProxyPassReverse rewrites Location headers in backend redirects so the browser is not sent to 127.0.0.1:3000.ProxyPreserveHost On passes the original Host header, which many frameworks need to build correct links.RequestHeader set X-Forwarded-Proto tells the app the client used HTTPS. mod_proxy already adds X-Forwarded-For and X-Forwarded-Host.Test and reload:
You can serve static files from Apache and send only an API path to the backend. Put exclusions before the general rule, because the first matching ProxyPass wins.
Keep trailing slashes consistent on both sides of a mapping. A mismatch such as /api to http://backend/api/ produces doubled or missing slashes.
Apache 2.4.47 and later can upgrade WebSocket connections through plain ProxyPass when proxy_http is loaded. For older versions or explicit control, use proxy_wstunnel:
Set timeouts to match your app:
connectiontimeout limits how long Apache waits to open a connection, timeout limits waiting for a response. Lower values fail fast when the backend is down.
byrequests spreads requests evenly. If the app keeps sessions in memory you need sticky sessions with a cookie, or better, move the session to a shared store. Health checks are available through mod_proxy_hcheck.
127.0.0.1 or a private network.ProxyRequests Off unless you really need a forward proxy.X-Forwarded-For only from your proxy. In Apache itself, behind another proxy, use mod_remoteip.SSLProxyEngine On and verify its certificate with SSLProxyVerify.mod_deflate at Apache, and let the backend skip it.| Error | Likely cause | Fix |
|---|---|---|
| 503 Service Unavailable | Backend is down or refused the connection | Check the app and port with curl http://127.0.0.1:3000/ |
| 502 Bad Gateway | Backend sent an invalid response or closed early | Read the app log and the Apache error_log |
| 504 Gateway Timeout | Backend is slower than timeout | Raise the timeout or fix the slow endpoint |
| Redirects go to localhost | Missing ProxyPassReverse | Add it for the same path |
| 503 with SELinux enabled | Apache is not allowed to connect out | sudo setsebool -P httpd_can_network_connect 1 |
ProxyPass forwards requests to the backend. ProxyPassReverse rewrites redirect headers coming back so clients see the public address.
Both work well. Apache is a good choice when you already use its modules and .htaccess; Nginx is common for pure proxying and high connection counts. Pick one per site and keep it consistent.
Turn it on when the backend builds absolute URLs or serves several domains from the Host header. Leave it off if the backend expects its own hostname.
Read X-Forwarded-For in the backend, and configure the framework to trust only your proxy address.
Enable proxy and proxy_http, keep ProxyRequests Off, and map paths with ProxyPass and ProxyPassReverse. Pass Host and protocol headers, add WebSocket and timeout settings for real apps, keep the backend private, and use balancer:// when you need several servers.