NGINX ignores Auth Basic

authenticationnginx

I have configured nginx to password protect a directory using auth_basic.
The password prompt comes up and the login works fine.

However… if I refuse to type in my credentials, and instead hit escape multiple times in a row, the page will eventually load w/o CSS and images.

In other words, continuously telling the login prompt to go away will at some point allow the page to load anyway.

Is this an issue with nginx, or my configuration?

Here is my virtual host:

31 server {
32    server_name sub.domain.com;
33    root /www/sub.domain.com/;
34
35    location / {
36        index index.php index.html;
37        root /www/sub.domain.com;
38        auth_basic  "Restricted";
39        auth_basic_user_file /www/auth/sub.domain.com;
40        error_page 404 = /www/404.php;
41    }
42
43    location ~ \.php$ {
44        include /usr/local/nginx/conf/fastcgi_params;
45     }
46 }

My server runs CentOS + nginx + php-fpm + xcache + mysql

Best Answer

Your configuration, nginx will use only the most specific location block. So when you request a *.php file it will use the location ~ .php$ block and not see the auth basic configuration.

The reason your .css, .js etc files work is because these do not match the PHP location block

You will need to add your auth basic configuration to the php file location block as well.