当前位置:网站首页>Openresty ngx Lua Execution stage
Openresty ngx Lua Execution stage
2022-07-05 02:18:00 【O Guatian Li Xia O】
openresty ngx_luaPhase de mise en œuvre
nginx httpPhase de mise en œuvre
nginx httpPhase de mise en œuvre
# ngx_http_core_module.h
typedef enum {
NGX_HTTP_POST_READ_PHASE = 0,
NGX_HTTP_SERVER_REWRITE_PHASE,
NGX_HTTP_FIND_CONFIG_PHASE,
NGX_HTTP_REWRITE_PHASE,
NGX_HTTP_POST_REWRITE_PHASE,
NGX_HTTP_PREACCESS_PHASE,
NGX_HTTP_ACCESS_PHASE,
NGX_HTTP_POST_ACCESS_PHASE,
NGX_HTTP_PRECONTENT_PHASE,
NGX_HTTP_CONTENT_PHASE,
NGX_HTTP_LOG_PHASE
} ngx_http_phases;
Description de la phase de mise en œuvre
NGX_HTTP_POST_READ_PHASE = 0,
* Accepter et lire la demande
NGX_HTTP_SERVER_REWRITE_PHASE,
* ModifierurlPhase, Il y a généralement une redirection 、Paramètres des variables
NGX_HTTP_FIND_CONFIG_PHASE,
* TrouverurlConfiguration correspondante,Si ça correspondlocation
NGX_HTTP_REWRITE_PHASE,
* Correspond àlocationAprès, Peut entrer à nouveau NGX_HTTP_SERVER_REWRITE_PHASE
NGX_HTTP_POST_REWRITE_PHASE,
* Vérifiezurl Si la phase a été exécutée 4,Si elle est exécutée, Retour à la phase 3
* Nombre maximal d'inspections 10,Si vous dépassez la limite, une erreur sera signalée
NGX_HTTP_PREACCESS_PHASE,
* Demande de limitation de vitesse des ressources, etc.
NGX_HTTP_ACCESS_PHASE,
* Contrôle d'accès,En cas de limitationipAccès à
NGX_HTTP_POST_ACCESS_PHASE,
* ValidationNGX_HTTP_ACCESS_PHASE(Contrôle d'accès)Résultats,Continuer si elle est acceptée
NGX_HTTP_PRECONTENT_PHASE,
* try_files En vigueur au moment de la directive
NGX_HTTP_CONTENT_PHASE,
* TraitementhttpContenu de la demande, Nécessite généralement une interaction avec l'application back - end
NGX_HTTP_LOG_PHASE
* Sortie du Journal
ngx_lua Phase de mise en œuvre
Ordre d'exécution
init_by_lua_block
init_worker_by_lua_block
set_by_lua_block
rewrite_by_lua_block
access_by_lua_block
content_by_lua_block
header_filter_by_lua_block
body_filter_by_lua_block
log_filter_by_lua_block
init_by_lua_block:nginxInitialisation、Exécuter au redémarrage,InhttpConfiguration dans le module
http {
include mime.types;
default_type application/octet-stream;
init_by_lua_block {
local uuid = require 'resty.jit-uuid';
uuid.seed();
}
...
}
init_by_lua_file:Rôle etinit_by_lua_blockMême chose., Bloc de code enregistré dans le fichier
http {
include mime.types;
default_type application/octet-stream;
init_worker_by_lua_file /usr/local/nginx/conf/init.lua
...
}
# /usr/local/nginx/conf/init.lua Contenu du fichier
local uuid = require 'resty.jit-uuid';
uuid.seed();
init_worker_by_lua_block:masterAprès le démarrage du processus, Exécuter le bloc de code associé ,InhttpConfiguration dans le module
# Peut être utilisé pour effectuer des tâches programmées 、 Bilan de santé de l'arrière - plan
http {
include mime.types;
default_type application/octet-stream;
init_worker_by_lua_block {
...
}
...
}
set_by_lua_block:Exécuter le bloc de code,Et renvoie les résultats,Inserver、location Paramètres dans le bloc d'instruction
Format syntaxique:set_by_lua_block $result {...}
* Cette commande est une commande de blocage , Le bloc d'instruction exécuté est aussi court que possible 、Allez,Évitez de prendre trop de temps
* Désactiver dans le bloc d'instruction :ngx.say()、ngx.exit()、ngx.sleep()Attendez les ordres.
server {
listen 80;
server_name localhost;
set $a "";
set_by_lua_block $a {
return "1";
}
location / {
root /usr/local/openresty/nginx/html;
index index.html index.htm;
}
...
}
rewrite_by_lua_block: Exécution de la phase de réécriture ,Oui.http、server、locationParamètres intermédiaires
Format syntaxique:rewrite_by_lua_block {...}
* Le bloc d'instruction s'exécute à la fin ,Peut passerrewrite_by_lua_no_postpone(Par défautoff)Modifier l'ordre d'exécution
* Tous lesngx api
# aLa valeur de2
server {
listen 80;
server_name localhost;
set $a "1";
rewrite_by_lua_block {
ngx_var_a="2";
}
set $a "3"
location / {
root /usr/local/openresty/nginx/html;
index index.html index.htm;
}
...
}
# httpConfiguration de la phase:rewrite_by_lua_no_postpone on
# aLa valeur de3
server {
listen 80;
server_name localhost;
set $a "1";
rewrite_by_lua_block {
ngx_var_a="2";
}
set $a "3"
location / {
root /usr/local/openresty/nginx/html;
index index.html index.htm;
}
...
}
access_by_lua_block:access Bloc d'instruction d'exécution de phase (Vérification des droits、Liste noire et blanche),Inhttp、server、locationParamètres intermédiaires
Format syntaxique:access_by_lua_block {...}
* Le bloc d'instruction s'exécute à la fin ,Peut passeraccess_by_lua_no_postpone(Par défautoff)Modifier l'ordre d'exécution
* Tous lesngx api
* Application: Conserver la liste en noir et blanc dans redis、En mémoire partagée, Définir dynamiquement la liste noire et blanche
content_by_lua_block: Exécution de la phase de traitement du contenu , Définir le contenu de sortie ,InlocationParamètres intermédiaires
Format syntaxique:content_by_lua_block {...}
* Tous lesngx api
* S'il est utilisé en même temps que d'autres déclarations de phase d'exécution de contenu ,content_by_lua_blockPeut ne pas être exécuté
location / {
content_by_lua_block {
ngx.say("hello gtlx");
}
echo "test" #Seulement la sortietest,Pas de sortiehello gtlx
}
content_by_lua_file:Aveccontent_by_lua_blockMême chose., Enregistrer l'instruction dans le fichier ,InlocationParamètres intermédiaires
Format syntaxique:content_by_lua_file file
* Tous lesngx api
location / {
content_by_lua_file /usr/local/openresty/file/test.lua
}
# Documentation:/usr/local/openresty/file/test.lua
hello gtlx
balancer_by_lua_block: Exécution de la phase de traitement du contenu ,InupstreamUtilisé dans l'énoncé
Format syntaxique:balancer_by_lua_block {...}
* upstreamUtilisationipPourbalancer_by_lua_block Adresse définie dans
* Désactivéapi:cosockets、light threads
upstream web-server {
server 172.18.0.2 #Sera ignoréserverSetipAdresse
balancer_by_lua_block {
... # Ça marche. ipAdresse
}
}
header_filter_by_lua_block: Phase de réponse ajouter 、 Supprimer l'en - tête de réponse ,Inhttp、server、locationParamètres intermédiaires
Format syntaxique:header_filter_by_lua_block {...}
* Désactivéapi:ngx.say()、ngx.redirect()、ngx.exec()Attendez.
# Ajouter un en - tête de réponse
location {
header_filter_by_lua_block {
ngx.header.test="hello gtlx"
}
echo "hello"
}
body_filter_by_lua_block: Phase de réponse modifier le corps de réponse ,Inhttp、server、locationParamètres intermédiaires
Format syntaxique:body_filter_by_lua_block {...}
* Désactivéapi:ngx.say()、ngx.redirect()、ngx.exec()Attendez.
# Convertir les données correspondantes en majuscules (ngx.arg[1]Obtenir les données de réponse,ngx.arg[2] Fin de la réponse )
# Produits:HELLO
location {
body_filter_by_lua_block {
ngx.arg[1] = string.upper(ngx.arg[1]);
}
echo "hello"
}
log_by_lua_block:Journal de sortie,Oui.http、server、locationParamètres intermédiaires
Format syntaxique:log_filter_by_lua_block {...}
* Inaccess_logPrécédemment appliqué, Ne remplace pas le courant access_logLog
* Désactivéapi:ngx.say()、ngx.redirect()、ngx.exec()Attendez.
location {
log_filter_by_lua_block {
ngx.log("hello gtlx")
}
echo "hello"
}
边栏推荐
- Serious bugs with lifted/nullable conversions from int, allowing conversion from decimal
- Video display and hiding of imitation tudou.com
- STL container
- Valentine's Day flirting with girls to force a small way, one can learn
- [Digital IC hand tearing code] Verilog edge detection circuit (rising edge, falling edge, double edge) | topic | principle | design | simulation
- Richview trvunits image display units
- CAM Pytorch
- [OpenGL learning notes 8] texture
- Visual studio 2019 set transparent background (fool teaching)
- Android advanced interview question record in 2022
猜你喜欢
Official announcement! The third cloud native programming challenge is officially launched!
MySQL backup and recovery + experiment
Video display and hiding of imitation tudou.com
Matrixone 0.2.0 is released, and the fastest SQL computing engine is coming
Binary tree traversal - middle order traversal (golang)
The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety
力扣剑指offer——二叉树篇
Lsblk command - check the disk of the system. I don't often use this command, but it's still very easy to use. Onion duck, like, collect, pay attention, wait for your arrival!
STM32 series - serial port UART software pin internal pull-up or external resistance pull-up - cause problem search
Phpstrom setting function annotation description
随机推荐
Erreur de type de datagramme MySQL en utilisant Druid
Variables in postman
RichView TRVStyle MainRVStyle
Naacl 2021 | contrastive learning sweeping text clustering task
February database ranking: how long can Oracle remain the first?
Write a thread pool by hand, and take you to learn the implementation principle of ThreadPoolExecutor thread pool
Yyds dry inventory swagger positioning problem ⽅ formula
How to make a cool ink screen electronic clock?
Advanced conditional statements of common SQL operations
Introduce reflow & repaint, and how to optimize it?
Tla+ through examples (XI) -- propositional logic and examples
How to build a technical team that will bring down the company?
Numpy library introductory tutorial: basic knowledge summary
A label making navigation bar
"2022" is a must know web security interview question for job hopping
【附源码】基于知识图谱的智能推荐系统-Sylvie小兔
STM32 series - serial port UART software pin internal pull-up or external resistance pull-up - cause problem search
Yolov5 model training and detection
MySQL backup and recovery + experiment
Android advanced interview question record in 2022