nginx的root和alias的区别

2024-12-01  本文已影响0人  Mr老朝

1、结论

2、location的最左匹配原则

location /bar {
    root /home/hfy/;
}

http://example.com/foo/bar/hello.html不会命中该location,因为从url中的/foo开始匹配,与location /bar不一致,不会命中,如果url更改为http://example.com/bar/hello.html 才会命中该规则

3、index index.html
location内部其实默认配置了一条规则index index.html

4、URL末尾斜杠/
http://example.com/foo/bar/:表示想要访问bar文件夹
http://example.com/foo/bar:表示想要访问bar文件,如果是文件夹nginx会自动重定向为http://example.com/foo/bar/

5、root最后的斜杠

6、alias最后的斜杠

7、最佳实践

上一篇 下一篇

猜你喜欢

热点阅读