I have an nginx reverse proxy server which feeds into a varnish cache with an apache backend.

The php is running as a fastcgi process started from apache.

I was attempting to get some php software working however the basic HTTP Authentication dialog was not accepting any usernames or passwords. I did some digging around and came up with this to put in a .htaccess file:

RewriteEngine On
RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization},L]

This has fixed the authentication issue with the basic HTTP auth.

Now I've been attempting to work out what exactly this has done, so my question is: why did adding this rewrite rule make the authentication start working?

All I could come up with at the moment is that somewhere along the chain of nginx -> varnish -> apache, apache was not recieving the auth headers. I would like to understand what is going on here so I can implement a change on the server level that will stop this from occuring elsewhere.

Can someone please clarify?

Thank you

  • "nginx -> varnish -> apache" -- i think you're doing it wrong. putting varnish between apache and nginx defeats the whole purpose of varnish, unless you've ensured that your nginx has been setup to not do any disc-based buffering – cnst Mar 20 '13 at 21:33

Loosing track of HTTP Authentication seems to be not an issue of nginx or Varnish.

This rewrite rule is not for making authentication header fields accessible to Apache but to the Fast-CGI backend (assuming authentication should be recognized inside PHP).

Authentication headers are usually hidden from Fast-CGI. You can

  • either use this RewriteRule hack to set the REMOTE_USER environment variable by hand;

  • or the mod_fastcgi configuration variable to pass headers to Fast-CGI:


-pass-header header (none)

The name of an HTTP Request Header to be passed in the request environment. This option makes available the contents of headers which are normally not available (e.g. Authorization) to a CGI environment


  • This explains it clearly :) – Antix Mar 13 '13 at 9:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.