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

别离应用 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的前面连起来;

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理