关于nginx:nginx笔记1alias和root对比

4次阅读

共计 530 个字符,预计需要花费 2 分钟才能阅读完成。

别离应用 alias 和 root 配置拜访 b.html

1.1 root->url 追加到 root 后定位

nginx 中的 root 配置:

location ^~ /app1/ {root /web;}

# 拜访: localhost/app1/b.html

b.html 在服务器的目录: /web/app1/b.html

  1. 拜访时 url 是什么?

    localhost/app1/b.html

  2. 拜访 url 映射到哪里?

    /app1/b.html:

    root+location 映射:/web/app1/b.html

1.2 alias->url 被 alias 替换

nginx 中的 alias 配置:

location ^~ /app2/ {alias /web;}
b.html 目录: /web/b.html
拜访: localhost/app2/b.html
论断: 相当于替换 

b.html 在服务器的目录: /web/b.html

  1. 拜访时 url 是什么?

    localhost/app2/b.html (url 和下面相似)

  2. 拜访 url 映射到哪里?

    /app2/b.html:

    alias 替换 location 映射:/web/b.html

1.3 小结

alias:location 的 uri 会被 alias 的替换;

root:location 的 uri 会追加到 root 的前面连起来;

正文完
 0