首先root块:
nginx的配置文件如下:
1
2
3
4
5
6
7
8
9
10
11
12
|
[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的配置文件如下:
1
2
3
4
5
6
7
8
9
10
11
12
|
# 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浏览器访问:
总结:
root:指令
/admin/index.html -----> /data/www/admin/index.html
alias:指令
/admin/index-----> /data/www/index.html
Nginx的认证模块:(支持多种加密方式,可以参考nginx官网)
auth_basic "admin com";
auth_basic_user_file /etc/nginx/passwd;
效果如下:
测试到此完成。
本文转自青衫解衣 51CTO博客,原文链接:http://blog.51cto.com/215687833/1903033