Apache 2.4 + PHP-FPM and Authorization headers

Apache 2.4 + PHP-FPM and Authorization headers

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Apache 2.4 + PHP-FPM and Authorization Headers

When configuring Apache 2.4 to proxy requests to a PHP-FPM backend using mod_proxy_fcgi, you might encounter a subtle but critical issue: the HTTP Authorization header is stripped before reaching the FastCGI process. This behavior breaks any application logic that relies on session persistence or token validation across the proxy boundary.

A common symptom of this misconfiguration appears when using external tools like APCu's status page. If you enable user caching and attempt to access protected endpoints, the login form may render correctly, but submitting valid credentials results in an immediate redirect or a 403 error. This happens because the backend PHP process executes as a separate user context without inheriting the authentication state established by Apache.

Why the Header Disappears

In traditional setups using mod_fastcgi, the FastCgiExternalServer directive includes a -pass-header option that explicitly forwards specific headers to the FastCGI wrapper. When switching to the more modern mod_proxy_fcgi architecture, this explicit passing mechanism is absent by default. The proxy module acts as an intermediary that often normalizes requests, inadvertently dropping headers deemed unsafe or unnecessary for internal routing unless explicitly preserved.

Unlike mod_fastcgi, which treats the backend as a direct socket connection where headers could be forwarded with minimal overhead, mod_proxy_fcgi integrates with Apache's broader proxy logic. This logic prioritizes security and clean request isolation, leading to the default stripping of sensitive headers like Authorization.

Preserving Headers with mod_proxy_fcgi

To restore functionality, you must explicitly instruct Apache to pass the header through. While the syntax differs from the legacy FastCGI approach, the solution involves configuring the ProxyPass directive with the -pass-header flag.

You can modify your virtual host configuration to include the following:

# Proxy all PHP requests to FPM
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/foo/bar/$1 -pass-header Authorization

# Ensure other sensitive headers are also passed if needed
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/foo/bar/$1 -pass-header "Authorization" -pass-header "Cookie"

The -pass-header flag ensures that the raw HTTP header is forwarded to the PHP-FPM socket without modification. This allows the PHP application to read $_SERVER['HTTP_AUTHORIZATION'] or $_COOKIE as expected, maintaining session continuity and enabling proper authentication checks.

Security Considerations

While passing headers restores functionality, it introduces a trade-off regarding security boundaries. By forwarding the Authorization header, you are essentially trusting that the client's connection to Apache is secure (typically over HTTPS) and that no man-in-the-middle attacks are occurring between the browser and your load balancer. If your setup involves multiple layers of proxies or reverse proxies, ensure that each layer correctly handles header forwarding to avoid data loss at deeper network levels.

Additionally, be cautious with the Cookie header. Passing cookies directly can expose session tokens if the internal FPM socket is accessible from untrusted sources. Since PHP-FPM typically runs on a local Unix socket or localhost TCP port, this risk is mitigated provided your firewall rules restrict access to 127.0.0.1 exclusively.

Alternative Approaches

If modifying Apache configuration feels restrictive due to complex proxy chains, consider integrating the authentication logic directly into the PHP application. This can involve checking for session tokens stored in a database rather than relying solely on client-side headers, though this adds complexity to the caching layer itself. For high-performance setups where header stripping is unacceptable, some administrators opt for mod_php or containerized backends that expose necessary environment variables instead of HTTP headers.

Ultimately, Apache 2.4 supports explicit header passing with mod_proxy_fcgi, but it requires deliberate configuration. Ignoring this detail leads to fragmented session management and broken caching strategies, particularly when leveraging tools like APCu for user cache entries.

Our network