fsfss21 发表于 2017-3-6 13:52:15

Nginx location段root和alias区别

首先root块:
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 _;
    indexindex.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 _;
    indexindex.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;
效果如下:


测试到此完成。

页: [1]
查看完整版本: Nginx location段root和alias区别