当前位置:网站首页>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"
}
边栏推荐
- Common bit operation skills of C speech
- 如何搭建一支搞垮公司的技術團隊?
- The most powerful new household god card of Bank of communications. Apply to earn 2100 yuan. Hurry up if you haven't applied!
- What is the length of SHA512 hash string- What is the length of a hashed string with SHA512?
- Comment mettre en place une équipe technique pour détruire l'entreprise?
- CAM Pytorch
- 【附源码】基于知识图谱的智能推荐系统-Sylvie小兔
- Process scheduling and termination
- Yolov5 model training and detection
- Learn tla+ (XII) -- functions through examples
猜你喜欢

Codeforces Global Round 19 ABC

Naacl 2021 | contrastive learning sweeping text clustering task

R语言用logistic逻辑回归和AFRIMA、ARIMA时间序列模型预测世界人口

Yolov5 model training and detection

如何做一个炫酷的墨水屏电子钟?

He was laid off.. 39 year old Ali P9, saved 150million

How to build a technical team that will bring down the company?

Interesting practice of robot programming 15- autoavoidobstacles

"C zero foundation introduction hundred knowledge and hundred cases" (72) multi wave entrustment -- Mom shouted for dinner

A tab Sina navigation bar
随机推荐
Pytorch register_ Hook (operate on gradient grad)
Pytorch common code snippet collection
JVM's responsibility - load and run bytecode
Unpool(nn.MaxUnpool2d)
WCF: expose unset read-only DataMember property- WCF: Exposing readonly DataMember properties without set?
Include rake tasks in Gems - including rake tasks in gems
The most powerful new household god card of Bank of communications. Apply to earn 2100 yuan. Hurry up if you haven't applied!
The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety
[Yu Yue education] National Open University spring 2019 0505-22t basic nursing reference questions
Write a thread pool by hand, and take you to learn the implementation principle of ThreadPoolExecutor thread pool
What sparks can applet container technology collide with IOT
Huawei machine test question: longest continuous subsequence
Yyds dry inventory jetpack hit dependency injection framework Getting Started Guide
【附源码】基于知识图谱的智能推荐系统-Sylvie小兔
Common bit operation skills of C speech
pytorch fine-tuning (funtune) : 镂空设计or 偷梁换柱
"C zero foundation introduction hundred knowledge and hundred cases" (72) multi wave entrustment -- Mom shouted for dinner
A label making navigation bar
Word processing software
如何搭建一支搞垮公司的技术团队?