auth_basic restricted files with php

kblessinggr nginx-forum at
Fri Feb 4 18:51:27 MSK 2011

I know this is old, but for those still finding this in search engines,
thats not the 'correct' fix, though it could work, The problem us using
a root path inside of the location block, if you move the root outside
of location and into the server { } block, then there is no need to have
a duplicated nested php block, nor is there a need to manually define
the document root since $document_root would be correctly filled by that


server {

  listen 80;
  root /usr/local/nginx/htdocs;

  location ~*/apc {
    auth_basic "Restricted";
    auth_basic_user_file /usr/local/nginx/htdocs/.htpasswd;

  location ~\.php$ {
    fastcgi_index index.php;

    #if the line isn't already in fastcgi_params
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include /usr/local/nginx/conf/fastcgi_params;

Posted at Nginx Forum:,74117,172193#msg-172193

More information about the nginx mailing list