Home >Backend Development >PHP Tutorial >Nginx and Lua execution order

Nginx and Lua execution order

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-28 08:28:491086browse

When Nginx processes each user request, it processes it in sequence according to several different phases, rather than according to the order in the configuration file.

The process of Nginx request processing is divided into 11 stages. The order of execution is

post-read, server-rewrite, find-config, rewrite, post-rewrite, preaccess, access, post-access, try-files , content, log.

  • post-read:
    Read request content phase
    Nginx starts running immediately after reading and parsing the request header
    For example, the module ngx_realip registers a handler in the post-read stage. Its function is to force Nginx to think that the source address of the current request is the value of a specified request header.
  • server-rewrite
    Server request address rewriting phase
    When the set configuration instructions of the ngx_rewrite module are written directly in the server configuration block, they basically run in the server-rewrite stage
  • find-config
    Configuration lookup phase
    This stage does not support Nginx module registration handlers. Instead, the Nginx core completes the matching between the current request and the location configuration block.
  • rewrite
    Location request address rewriting phase
    When the directives of the ngx_rewrite module are used in the location block, they run in this rewrite phase.
    In addition, the instructions of the ngx_set_misc (set md5, encode_base64, etc.) module, as well as the set_by_lua instructions and rewrite_by_lua instructions of the ngx_lua module are also at this stage.
  • post-rewrite
    Request address rewrite submission phase
    The Nginx core completes the "internal jump" operation required by the rewrite phase, if there is such a requirement in the rewrite phase.
  • preaccess
    Access permission check preparation phase
    The standard modules ngx_limit_req and ngx_limit_zone run at this stage. The former can control the access frequency of requests, while the latter can limit the concurrency of access.
  • access
    Access permission check phase
    The standard module ngx_access, the third-party module ngx_auth_request, and the access_by_lua directive of the third-party module ngx_lua run at this stage.
    Configuration instructions are mostly used to perform access control tasks, such as checking the user's access rights and checking whether the user's source IP address is legal
  • post-access
    Access permission check submission phase
    It is mainly used to cooperate with the access stage to implement the satisfy function of the configuration instruction provided by the standard ngx_http_core module.
    satisfy all (relationship)
    satisfy any(or relationship)
  • try-files
    Configuration item try_files processing stage
    Specifically used to implement the functions of the standard configuration directive try_files
    If the file system objects corresponding to the first N-1 parameters do not exist, the try-files phase will immediately initiate an "internal jump" to the URI specified by the last parameter (i.e., the Nth parameter).
  • content
    Content generation stage
    The content phase of Nginx is the most important of all request processing phases, because the configuration instructions running in this phase are generally responsible for generating "content"
    And output the HTTP response mission.
  • log
    Log module processing stage
    Record log
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above introduces the execution sequence of Nginx and Lua, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn