介绍

nginx配置文件中常用root指定当前项目根目··
alias也是用来替换用户指定的项目目录的
接下来说一下他们的差别

项目配置文件
[root@localhost webroot]# tree
.
├── code
│ ·· └── test2.html
└── test.html

1 directory, 2 files
[root@localhost webroot]# cat test.html
aaa
[root@localhost webroot]# cat code/test2.html
bbb

nginx配置
alias重定向项目目··
location /code/
{
alias /data/webroot/;
}
访问结果
[root@localhost webroot]# curl http://192.168.1.128/html/test.html
aaa
访问到文件:/data/webroot/tesst.html

root重定向项目目··

location /code/
{
root /data/webroot/;
}
访问同样结果
[root@localhost webroot]# curl http://192.168.1.128/code/test2.html
bbb
访问到的文件··/data/webroot/code/tesst2.html

总结
nginx使用root来指定··$document_root”变··,请求访问到的文件是··$document_root··+URL
使用alias访问的就是··$document_root··+"匹配的后面一部分"

绝对路径名对应的当前请求的root或alias指定的路径时,所有的符号链接解析为真正的路径

nginx教程

第一·· nginx安装基本引导和进程信号

02-nginx IO模型

03-nginx负载均衡

04-nginx的root和alias区别

05-nginx limit_req和limit_conn_zone