Nginx的root和alias区别

1.root

下面举例说明:

location /i/ {
  root /data/w3;
}

请求 http://foofish.net/i/top.gif 这个地址时,那么在服务器里面对应的真正的资源是 /data/w3/i/top.gif文件

注意:真实的路径是root指定的值加上location指定的值 。

这里在提一个其他的知识点:http模块的index

http模块名叫index,它有一个指令叫index,默认值是index.html。

这个模块的用途是:任何以/结尾的url,都尝试一下加上index.html(可配),看看能不能访问,如果能访问就返回这个文件的内容。

1.alias

  • alias会与location 后的前缀密切配合。比如location /a {alias b},如果你访问/a/c.html,实际会访问/b/c.html,它会把前缀替换掉。
  •  alias 正如其名,alias指定的路径是location的别名,不管location的值怎么写,资源的 真实路径都是 alias 指定的路径 

还是举例说明:

location /i/ {
  alias /data/w3/;
}

  同样请求 http://foofish.net/i/top.gif 时,在服务器查找的资源路径是: /data/w3/top.gif

猜你喜欢

转载自www.cnblogs.com/Tao9/p/11960406.html
今日推荐