NGINX保护文件不起作用

时间:2015-04-26 20:37:42

标签: php nginx fastcgi .htpasswd

我想使用nginx中的auth_basic方法密码保护我的web文件夹中的文件。我在互联网上搜索了一些代码,发现了这个:

server {
    listen 80;
    root /var/www;
    index index.php index.html index.htm;

    location ~ \.php$ {
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
    }

    location ~ /tools/admin\.php$ {
            auth_basic "Restricted Area";
            auth_basic_user_file /etc/nginx/.htpasswd;
            root /var/www;
            try_files $uri =404;
            fastcgi_pass unix:/tmp/php5-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
            fastcgi_read_timeout 300;
    }
}

我想保护文件/tools/admin.php,但它似乎不起作用,因为我没有得到任何密码弹出窗口。我也重新启动了nginx。

0 个答案:

没有答案