Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question
    
"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
add comment

1 Answer

up vote 2 down vote accepted

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:

FastCgiServer:
[...]

-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

[...]

share|improve this answer
    
This explains it clearly :) –  Antix Mar 13 '13 at 9:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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