NGINX openrestry(指令的执行顺序)

Nginx的指令的执行顺序:

一、post-read

二、server-rewrite

三、find-config

四、rewrite

五、post-rewrite

六、preaccess

七、access

八、post-access

九、try-files

十、content阶段:

  这个阶段的这么多的指令只能有一种胜出。

  执行的顺序是:如果1里面有就从里面选择一个执行,如果1里面没有就让2执行,如果2没有就让3执行,如果3内有就让4执行。

1、ngx_echo模块的echo指令、echo_exec指令、echo_location指令

  ngx_proxy模块的proxy_pass指令

  ngx_lua模块的content_by_lua指令

  用一种指令有的可以写几次,比如echo。

location /test {
  echo hello;
  echo world;
}

  ngx_lua模块的ngx.say函数和ngx_echo模块的echo函数是一样的

location /test {
  content_by_lua 'ngx.say("hello") ngx.say("world")';
}

2、ngx_index模块的index指令:

  处理以'/'结尾的请求

location / {
  root /var/www/;
  index index.htm index.html;
}

  当用户请求'/'地址时,Nginx会自动在/var/www/index.htm目录下寻找这个文件,如果找到,则直接发起内部跳转到新的'/index.html'这个新的地址,如果不存在,则继续找/var/www/index.html这个文件,如果找得到,则直接发起内部跳转到'/index.html'这个地址,如果不存在,就交给后续的模块进行处理,如果都处理不了,就报403的错误。

内部跳转:

  ngx_index模块的index指令

  echo模块的echo_exec指令

  rewrite指令

3、ngx_autoindex模块的autoindex指令:

  处理以'/'结尾的请求

  自动生成目录索引页

location / {
root /var/www/;
index index.html;
autoindex on;
}

  当请求到来时,当/var/www/index.html的页面不存在时,会显示/var/www/下的文件目录列表;当index.html的存在时,会优先执行ngx_index模块的index指令,直接发生内部跳转。

4、ngx_static模块的静态资源指令:

  处理不以'/'结尾的网页

  专门用来处理和输出静态资源内容的

十一、log

猜你喜欢

转载自www.cnblogs.com/erdanyang/p/10771753.html