Apache as a Production Reverse Proxy: A Practical Configuration Guide

Tim Rabbetts | December 1, 2026

Apache HTTP Server is commonly introduced as a web server that delivers files from a document root. That description is accurate, but incomplete. Apache can also sit at the edge of an application, accepting public HTTP requests and forwarding selected paths to services running on private ports or internal hosts.

That reverse-proxy role is useful when a legacy Apache installation needs to front a newer application, when several services must share one hostname, or when TLS, access control and operational policy should be managed in one place. Apache’s mod_proxy family provides the routing layer, while modules such as mod_headers, mod_ssl and mod_status add policy and visibility.

This article concentrates on a production-minded pattern: Apache receives requests for https://example.test, serves static assets locally, and forwards /app/ to an application listening on 127.0.0.1:8080. The same principles apply when the backend is a container, a separate virtual machine or a small cluster.

What a reverse proxy actually does

In a reverse-proxy arrangement, the browser communicates with Apache rather than directly with the backend. Apache forwards the request, receives the backend response and sends that response to the client. The backend therefore does not need to be publicly reachable.

That separation can provide several practical benefits:

  • Only Apache needs to be exposed to the internet.
  • TLS certificates and HTTP security policy can be managed at the edge.
  • One hostname can route different URL paths to different services.
  • Backend ports can remain private and protected by a firewall.
  • Apache can provide logging, request limits and access controls consistently.

Apache’s official reverse-proxy guide describes this model as a gateway in which backend processes have no direct connection to the external network. It also highlights security, availability and centralised authentication as common reasons to use the pattern. Read the Apache reverse-proxy guide. ([httpd.apache.org](https://httpd.apache.org/docs/2.4/howto/reverse_proxy.html?utm_source=openai))

Do not confuse a reverse proxy with a forward proxy. A forward proxy allows clients to request arbitrary external destinations. A reverse proxy exposes specific services that you control. For a normal reverse-proxy deployment, ProxyRequests should remain Off. Enabling forward proxying without securing it can create an open proxy that is abused to relay traffic. Apache’s mod_proxy documentation explicitly warns about this distinction. ([httpd.apache.org](https://httpd.apache.org/docs/2.4/en/mod/mod_proxy.html?utm_source=openai))

A minimal virtual host

Start with a dedicated virtual host rather than adding proxy rules to a generic configuration. The example below assumes that Apache terminates HTTPS and forwards only the /app/ path to an application on the same machine.

<VirtualHost *:443>
    ServerName example.test

    SSLEngine On
    SSLCertificateFile /etc/ssl/example.test/fullchain.pem
    SSLCertificateKeyFile /etc/ssl/example.test/privkey.pem

    ProxyRequests Off
    ProxyPreserveHost On

    ProxyPass        "/app/" "http://127.0.0.1:8080/"
    ProxyPassReverse "/app/" "http://127.0.0.1:8080/"

    ErrorLog  ${APACHE_LOG_DIR}/example-error.log
    CustomLog ${APACHE_LOG_DIR}/example-access.log combined
</VirtualHost>

The important pair is ProxyPass and ProxyPassReverse. The first maps an incoming local path to a backend URL. The second adjusts redirect-related response headers generated by the backend, such as Location, so that clients continue to use the public address rather than being sent to the internal service.

ProxyPassReverse does not rewrite every URL contained in an HTML response. It handles particular response headers, not arbitrary links, scripts or API payloads. If an application emits absolute internal URLs in its content, fix the application’s public base URL where possible. Apache documents mod_proxy_html as a separate option for content rewriting, but rewriting response bodies adds complexity and should not be the default solution. ([httpd.apache.org](https://httpd.apache.org/docs/2.4/mod/mod_proxy.html.en?utm_source=openai))

Trailing slashes deserve attention. If the local path ends in a slash, the backend mapping should normally end in a slash too. Mismatched slash conventions can produce unexpected paths. Apache also evaluates proxy rules in configuration order, with the first matching rule winning, so put more specific exclusions or paths before broader ones. ([httpd.apache.org](https://httpd.apache.org/docs/2.4/en/mod/mod_proxy.html?utm_source=openai))

Preserving the public host and scheme

Applications frequently need to know how the client reached them. This affects absolute URL generation, cookie security, redirects and canonical URLs. Without the correct information, an application may generate links to 127.0.0.1, redirect from HTTPS to HTTP or mark secure cookies incorrectly.

ProxyPreserveHost On passes the original HTTP Host header to the backend instead of replacing it with the backend hostname. Whether you need it depends on the application and its virtual-host configuration, but it is commonly appropriate when the backend must generate URLs for the public hostname.

Also make the original scheme explicit. A backend receiving plain HTTP from Apache cannot automatically know that the browser used HTTPS. Many frameworks understand the standard X-Forwarded-Proto header, but they must be configured to trust it only when the request came through a trusted proxy.

<VirtualHost *:443>
    ServerName example.test

    ProxyRequests Off
    ProxyPreserveHost On

    RequestHeader set X-Forwarded-Proto "https"
    RequestHeader set X-Forwarded-Host "%{HTTP_HOST}s"

    ProxyPass        "/app/" "http://127.0.0.1:8080/"
    ProxyPassReverse "/app/" "http://127.0.0.1:8080/"
</VirtualHost>

Header handling is powerful, so avoid blindly appending values received from untrusted clients. Prefer set when Apache is the trusted edge and should define the value. If another trusted proxy sits in front of Apache, design the chain deliberately: decide which hop is allowed to set forwarding headers and strip or replace values at the appropriate boundary.

Apache’s mod_headers documentation notes that request headers are modified before the content handler runs and that directive placement and order affect the result. It also distinguishes normal and always response-header processing, which matters when headers must survive error responses or internal redirects. ([httpd.apache.org](https://httpd.apache.org/docs/current/mod/mod_headers.html?utm_source=openai))

Keep backend services private

A reverse proxy is not a substitute for network isolation. Bind a local backend to the loopback interface when Apache and the application share a host, or restrict the backend port with a firewall when the service runs elsewhere.

ss -ltnp | grep 8080
curl --fail --silent --show-error http://127.0.0.1:8080/health

The first command helps confirm what is listening. The second tests the backend directly from the server. A successful local request does not prove that Apache is routing correctly, but a failed local request means the proxy cannot succeed until the service, port or bind address is fixed.

Keep ProxyRequests Off in the relevant server or virtual-host configuration. If you are proxying only a small number of paths, define only those paths rather than forwarding the entire site by default. A narrow configuration reduces accidental exposure and makes reviews easier.

Set sensible connection and response behaviour

A proxy can consume resources while waiting for a slow or broken backend. Set a backend timeout appropriate to the application rather than allowing every request to wait indefinitely. The correct value depends on the endpoint: a health check, ordinary page request and long-running report may need different policies.

<Proxy "http://127.0.0.1:8080/">
    ProxySet connectiontimeout=5 timeout=30
</Proxy>

ProxyPass        "/app/" "http://127.0.0.1:8080/" connectiontimeout=5 timeout=30
ProxyPassReverse "/app/" "http://127.0.0.1:8080/"

Do not copy these numbers blindly. A 30-second timeout may be too short for a legitimate export and far too long for a latency-sensitive API. Measure normal response times, define an upper bound for each class of request and make the application enforce compatible limits as well.

Long-lived connections require separate thought. Server-sent events, streaming downloads and WebSockets may need buffering, timeout and protocol settings that differ from ordinary request-response traffic. Apache HTTP Server 2.4.47 and later can handle protocol upgrades through mod_proxy_http using the upgrade parameter, while older deployments may require the WebSocket-specific module and configuration described in Apache’s documentation. Check the installed version before applying an example. ([httpd.apache.org](https://httpd.apache.org/docs/2.4/mod/mod_proxy.html?utm_source=openai))

Routing several services safely

Once one path works, it is tempting to add broad rules quickly. Resist that approach. Make the public contract explicit:

ProxyPass        "/api/"  "http://127.0.0.1:9000/"
ProxyPassReverse "/api/"  "http://127.0.0.1:9000/"

ProxyPass        "/admin/" "http://127.0.0.1:9100/"
ProxyPassReverse "/admin/" "http://127.0.0.1:9100/"

ProxyPass        "/app/"  "http://127.0.0.1:8080/"
ProxyPassReverse "/app/"  "http://127.0.0.1:8080/"

Put the most specific paths first if rules could overlap. For example, an exclusion for /app/static/ must be evaluated before a general /app/ proxy rule if static files should be served locally.

ProxyPass "/app/static/" "!"
Alias "/srv/example/static/" "/app/static/"

ProxyPass        "/app/" "http://127.0.0.1:8080/"
ProxyPassReverse "/app/" "http://127.0.0.1:8080/"

Use this pattern only when the local mapping and directory permissions are correct. An exclusion that points to a missing or unexpectedly writable directory can turn a routing change into a content or security problem.

Load balancing without hiding application state

Apache can distribute requests across backend members using a balancer. A basic configuration might look like this:

<Proxy "balancer://appcluster">
    BalancerMember "http://10.0.1.21:8080" route=node1
    BalancerMember "http://10.0.1.22:8080" route=node2
    ProxySet lbmethod=byrequests
</Proxy>

ProxyPass        "/app/" "balancer://appcluster/"
ProxyPassReverse "/app/" "balancer://appcluster/"

Load balancing does not automatically make an application horizontally scalable. Sessions, uploaded files, queues, caches and database connections may still be tied to one instance. Prefer shared or externalised state where appropriate. If sticky sessions are unavoidable, document the failure behaviour: a node outage may invalidate sessions even though the proxy continues routing traffic.

Health checking also needs an application-level design. A process listening on a port is not necessarily ready to serve requests. Expose a lightweight readiness endpoint that checks only the dependencies required for serving traffic, and keep it separate from an expensive diagnostic endpoint.

Headers, caching and compression: change one concern at a time

Apache can modify response headers, but setting a header is not the same as implementing a complete caching policy. Cache directives must match whether the response is public, personalised, immutable or sensitive.

LoadModule headers_module modules/mod_headers.so

<Location "/app/assets/">
    Header set Cache-Control "public, max-age=31536000, immutable"
</Location>

<Location "/app/">
    Header set Cache-Control "private, no-store"
</Location>

Use long-lived caching only for assets whose URLs change when their contents change, such as files containing a content hash. Applying an immutable policy to an unversioned stylesheet can leave users with stale code for months.

Be equally cautious with security headers. A reverse proxy can add useful defaults, but policies such as Content Security Policy, frame restrictions and cross-origin controls must reflect the actual application. Test them in a staging environment before enforcing a strict policy, and do not add headers simply because a scanner recommends them without understanding their effect.

Logs are part of the proxy contract

When Apache fronts an application, there are two useful perspectives: what the client sent to Apache and what Apache received from the backend. Start with separate access and error logs for the virtual host. Include request time and status information if your platform’s logging format supports it.

LogFormat "%v %a %{%Y-%m-%dT%H:%M:%S%z}t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %D" proxy_combined

CustomLog ${APACHE_LOG_DIR}/example-access.log proxy_combined
ErrorLog  ${APACHE_LOG_DIR}/example-error.log

Do not log secrets, authorisation tokens or sensitive request bodies. Treat forwarded client IP headers as untrusted unless they come from a proxy you control. If another load balancer is in front of Apache, configure trusted proxy handling deliberately rather than assuming that the first address in a header is genuine.

For operational visibility, mod_status can expose server activity, but restrict it to administrators or an internal network. Never publish a detailed status endpoint anonymously on the public internet.

Test configuration before reloading

Configuration changes should follow a repeatable sequence: edit, validate, inspect the diff, reload gracefully and test the public path. Apache provides apachectl configtest, equivalent to apachectl -t, to parse the configuration and report syntax errors.

sudo apachectl configtest
sudo apachectl -k graceful

curl --head --fail https://example.test/app/
curl --head --fail https://example.test/app/health
sudo tail -f /var/log/apache2/example-error.log

A syntax check catches malformed directives, but it cannot prove that the backend is reachable, that a certificate matches the hostname or that an application generates correct redirects. Test at least one normal response, one backend error, one redirect and one authenticated path where relevant.

Apache’s graceful restart causes existing child processes to finish current requests while new children use the re-read configuration. The documentation also notes that configuration syntax is checked before the restart is attempted, reducing the chance of taking down a working service because of a typo. ([httpd.apache.org](https://httpd.apache.org/docs/2.4/stopping.html?utm_source=openai))

A practical troubleshooting sequence

  1. Check DNS and TLS. Confirm that the hostname resolves to the intended edge server and that the certificate covers the hostname.
  2. Check Apache’s loaded configuration. Run apachectl configtest and inspect enabled virtual hosts and modules using the commands provided by your distribution.
  3. Test the backend locally. Use curl against the backend address and port from the Apache host.
  4. Test the public route. Compare the public response status, headers and redirect location with the direct backend response.
  5. Read both logs. A 502 or 503 may be caused by a stopped service, a refused connection, a timeout or an application-level failure.
  6. Check path rewriting. Confirm whether the backend expects /, /app/ or another base path, and verify trailing slashes.
  7. Check trust settings. If URLs, cookies or client IPs are wrong, inspect Host, X-Forwarded-Proto and other forwarded headers.

Production checklist

  • Keep ProxyRequests Off.
  • Expose only the paths that need proxying.
  • Keep backend ports private and bind local services to loopback where possible.
  • Use both ProxyPass and ProxyPassReverse for ordinary HTTP reverse proxying.
  • Align trailing slashes and order overlapping rules from most specific to least specific.
  • Configure the application to trust forwarded headers only from known proxies.
  • Set backend timeouts based on measured behaviour rather than copying arbitrary values.
  • Separate public, private and immutable caching policies.
  • Keep proxy logs useful without recording credentials or sensitive payloads.
  • Run a syntax check before every reload and use graceful restarts for normal deployments.
  • Test redirects, errors, authentication, streaming and WebSocket paths separately when they are part of the application.

Apache is not merely a legacy front end. Used deliberately, it provides a stable boundary between public HTTP traffic and changing application services. The most reliable deployments keep the configuration narrow, make backend assumptions explicit, preserve only the headers the application needs and treat testing and observability as part of the proxy design rather than afterthoughts.