要实现网站所有目录均通过验证才能访问,可将nginx配置文件加为如下内容:
location ^~ / {
auth_basic "Authorized users only";
auth_basic_user_file wttxAuth.conf;
}
这样访问网站及网站下所有文件均出现提示验证了。
注意,加上认证之后该目录下的PHP将不会被解析,会出现下载提示,如果想可以解析PHP可以将上面的配置改为:
location ^~ / {
location ~ .*.(php|php5)?$ {
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
auth_basic "Authorized users only";
auth_basic_user_file 这里写前面脚本返回的文件路径;
}
|