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'm trying to exempt a location from basic_auth whereas the rest of the site does require it. Reading up on it my config should work but for some reason it still returns 401 for /asd/qwe/.

server {
    server_name domain.com www.domain.com;

    root /var/www/domains/domain.com/htdocs/public;

    index index.php index.htm;

    location / {
        location ~ \.php$ {
            include /etc/nginx/fastcgi_params;
            fastcgi_pass unix:/var/run/php5-fpm.domain.com.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME /var/www/domains/domain.com/htdocs/public$fastcgi_script_name;
        }

      auth_basic "Restricted";
      auth_basic_user_file /var/www/domains/htpasswd/domain.com.htpasswd;

    }

    location /asd/qwe/ {
          auth_basic off;
          allow all;

        location ~ \.php$ {
            include /etc/nginx/fastcgi_params;
            fastcgi_pass unix:/var/run/php5-fpm.domain.com.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME /var/www/domains/domain.com/htdocs/public$fastcgi_script_name;
        }
    }

}
share|improve this question

2 Answers 2

Finnaly found a solution to it:

server {

server_name domain.com www.domain.com;

root /var/www/domains/domain.com/htdocs/public;

access_log /var/log/nginx/domains/domain.com/access.log;

error_log /var/log/nginx/domains/domain.com/error.log; index index.php index.htm;

  auth_basic_user_file /var/www/domains/htpasswd/domain.com.htpasswd;

location ~ /.svn/ {
    deny all;
}
location ~ /.htaccess {
    deny all;
}

location ^~ /psp/callback/ {
      auth_basic off;

      include /etc/nginx/fastcgi_params;
      fastcgi_pass unix:/var/run/php5-fpm.domain.com.sock;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME /var/www/domains/domain.com/htdocs/public$fastcgi_script_name;
 }

location / {
  auth_basic "Restricted";
}

    location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass unix:/var/run/php5-fpm.domain.com.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /var/www/domains/domain.com/htdocs/public$fastcgi_script_name;
      }

# Zend Framework rewrite
if (!-e $request_filename) {
    set $zfRewrite 1;
}
if ($zfRewrite = 1) {
    rewrite ^.*$ /index.php last;
}

}

share|improve this answer

Unless you are using literal matches (the = location prefix), processing stops at the first match. Put your /asd/qwe block above the / block and it should work.

For more information, see the nginx documentation on the location directive:

http://wiki.nginx.org/HttpCoreModule#location

share|improve this answer
    
Forgot to mention I've the following in the end as well which I think is the source of the issue: if (!-e $request_filename) { set $zfRewrite 1; } if ($zfRewrite = 1) { rewrite ^.*$ /index.php last; } –  user2108948 Sep 6 '13 at 7:00

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.