Nginx and Lua execution order
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
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.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to configure Nginx in Windows? Install Nginx and create a virtual host configuration. Modify the main configuration file and include the virtual host configuration. Start or reload Nginx. Test the configuration and view the website. Selectively enable SSL and configure SSL certificates. Selectively set the firewall to allow port 80 and 443 traffic.

You can query the Docker container name by following the steps: List all containers (docker ps). Filter the container list (using the grep command). Gets the container name (located in the "NAMES" column).

Docker container startup steps: Pull the container image: Run "docker pull [mirror name]". Create a container: Use "docker create [options] [mirror name] [commands and parameters]". Start the container: Execute "docker start [Container name or ID]". Check container status: Verify that the container is running with "docker ps".

How to confirm whether Nginx is started: 1. Use the command line: systemctl status nginx (Linux/Unix), netstat -ano | findstr 80 (Windows); 2. Check whether port 80 is open; 3. Check the Nginx startup message in the system log; 4. Use third-party tools, such as Nagios, Zabbix, and Icinga.

Create a container in Docker: 1. Pull the image: docker pull [mirror name] 2. Create a container: docker run [Options] [mirror name] [Command] 3. Start the container: docker start [Container name]

How to configure an Nginx domain name on a cloud server: Create an A record pointing to the public IP address of the cloud server. Add virtual host blocks in the Nginx configuration file, specifying the listening port, domain name, and website root directory. Restart Nginx to apply the changes. Access the domain name test configuration. Other notes: Install the SSL certificate to enable HTTPS, ensure that the firewall allows port 80 traffic, and wait for DNS resolution to take effect.

Starting an Nginx server requires different steps according to different operating systems: Linux/Unix system: Install the Nginx package (for example, using apt-get or yum). Use systemctl to start an Nginx service (for example, sudo systemctl start nginx). Windows system: Download and install Windows binary files. Start Nginx using the nginx.exe executable (for example, nginx.exe -c conf\nginx.conf). No matter which operating system you use, you can access the server IP

Question: How to start Nginx? Answer: Install Nginx Startup Nginx Verification Nginx Is Nginx Started Explore other startup options Automatically start Nginx
