Nginx-location细节解析

2018-01-11  本文已影响0人  lazyguy

title: nginx中location细节解析
date: 2016-12-16 11:23:56
tags: nginx location
categories: nginx


location模块的路径匹配流程图:

image.png

可以简单记为起作用的顺序是
=(精准匹配) > (^~字符串前缀匹配,不考虑正则结果) > (正则location匹配*) > (字符串前缀匹配)

其中多个匹配的正则location起作用的顺序跟在conf文件中的顺序相关

location中的其他常见指令

root 寻址开始的根

可以在server context和location context下定义root,但是通常
为了避免冗余配置,在server上下文中配置一个root最好

error_page 错误页面

error_page 404 /404.html
可以单独配置在其中一个location模块中

location /a {
               root /Users/tobi/Pictures/; 
               error_page 404.html #放在上述目录下的/Users/tobi/Pictures/a/404.html
            } 

或者单独为error_page配置一个地址

     error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

autoindex(允许列出目录下的所有文件,默认关闭)

index(默认页面)

deny(禁止访问某个路径)

上一篇 下一篇

猜你喜欢

热点阅读