How to get nginx to pass HTTP_AUTHORIZATION header to Apache
Posted
by
codeinthehole
on Server Fault
See other posts from Server Fault
or by codeinthehole
Published on 2011-05-09T10:28:09Z
Indexed on
2013/10/26
22:00 UTC
Read the original article
Hit count: 333
nginx
Am using Nginx as a reverse proxy to an Apache server that uses HTTP Auth. For some reason, I can't get the HTTP_AUTHORIZATION header through to Apache, it seems to get filtered out by Nginx. Hence, no requests can authenticate.
Note that the Basic auth is dynamic so I don't want to hard-code it in my nginx config.
My nginx config is:
server {
listen 80;
server_name example.co.uk ;
access_log /var/log/nginx/access.cdk-dev.tangentlabs.co.uk.log;
gzip on;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 120;
location / {
proxy_pass http://localhost:81/;
}
location ~* \.(jpg|png|gif|jpeg|js|css|mp3|wav|swf|mov|doc|xls|ppt|docx|pptx|xlsx|swf)$ {
if (!-f $request_filename) {
break;
proxy_pass http://localhost:81;
}
root /var/www/example;
}
}
Anyone know why this is happening?
Update - turns out the problem was something I had overlooked in my original question: mod_wsgi. The site in question here is a Django site, and it turns out that Apache does get the auth variables passed through, however mod_wsgi filters them out.
The resolution is to use:
WSGIPassAuthorization On
See http://www.arnebrodowski.de/blog/508-Django,-mod_wsgi-and-HTTP-Authentication.html for more details
© Server Fault or respective owner