首先root块:
nginx的配置文件如下:
[root@localhost www]# cat /etc/nginx/conf.d/admin.conf
server
{
listen 80;
server_name _;
index index.html index.php;
location /admin/ {
root /data/www/;
auth_basic "admin com";
auth_basic_user_file /etc/nginx/passwd;
}
}root路径文件存放:
通过浏览器访问效果:
然后alias块:
nginx的配置文件如下:
# cat /etc/nginx/conf.d/admin.conf
server
{
listen 80;
server_name _;
index index.html index.php;
location /admin/ {
alias /data/www/;
auth_basic "admin com";
auth_basic_user_file /etc/nginx/passwd;
}
}web访问效果:
再次切回root,创建admin目录:
web浏览器访问:
Nginx的认证模块:(支持多种加密方式,可以参考nginx官网)
auth_basic "admin com";
auth_basic_user_file /etc/nginx/passwd;
效果如下:
测试到此完成。
本文出自 “LINUX Super梦” 博客,请务必保留此出处http://215687833.blog.51cto.com/6724358/1903033
原文:http://215687833.blog.51cto.com/6724358/1903033