How to get PHP_AUTH_USER and PHP_AUTH_PW available in nginx?

I have a Magento module that asks for $_SERVER['PHP_AUTH_USER'] and $_SERVER['PHP_AUTH_PW'] variables.

In its documentation, the following setup for apache is proposed:

SetEnvIfNoCase Authorization "Basic ([a-z0-9=]+)" REMOTE_AUTHORIZATION=$

But I'm using nginx. What can I add in my .conf file to support these variables?


That should do the trick:

fastcgi_param PHP_AUTH_USER $remote_user;
fastcgi_param PHP_AUTH_PW $http_authorization;

Edit: Please read the comments on my answer. This will only allow you to access the variables if the user has authenticated against nginx and not against PHP. It's not possible to access PHP variables within nginx, simply because nginx is before PHP and only communicates via the FastCGI protocol with PHP. This is different if you're using Apache httpd with modphp.