当前位置:网站首页>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"
}
边栏推荐
- Yyds dry inventory swagger positioning problem ⽅ formula
- Exploration of short text analysis in the field of medical and health (I)
- JVM's responsibility - load and run bytecode
- Mysql database | build master-slave instances of mysql-8.0 or above based on docker
- Android advanced interview question record in 2022
- Open source SPL optimized report application coping endlessly
- Application and Optimization Practice of redis in vivo push platform
- How to make a cool ink screen electronic clock?
- Official announcement! The third cloud native programming challenge is officially launched!
- Pytorch common code snippet collection
猜你喜欢

Missile interception -- UPC winter vacation training match

官宣!第三届云原生编程挑战赛正式启动!

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

The MySQL team development specifications used by various factories are too detailed. It is recommended to collect them!

The steering wheel can be turned for one and a half turns. Is there any difference between it and two turns

Icu4c 70 source code download and compilation (win10, vs2022)

MATLB | multi micro grid and distributed energy trading

Summary and practice of knowledge map construction technology

Restful fast request 2022.2.1 release, support curl import

Three properties that a good homomorphic encryption should satisfy
随机推荐
[Yu Yue education] National Open University spring 2019 0505-22t basic nursing reference questions
179. Maximum number - sort
STL container
172. Zero after factorial
丸子百度小程序详细配置教程,审核通过。
RichView TRVStyle MainRVStyle
Win:将一般用户添加到 Local Admins 组中
[OpenGL learning notes 8] texture
Limited query of common SQL operations
The most powerful new household god card of Bank of communications. Apply to earn 2100 yuan. Hurry up if you haven't applied!
Application and Optimization Practice of redis in vivo push platform
Pytorch common code snippet collection
JVM's responsibility - load and run bytecode
[understanding of opportunity -38]: Guiguzi - Chapter 5 flying clamp - warning one: there is a kind of killing called "killing"
Win:使用 Shadow Mode 查看远程用户的桌面会话
Abacus mental arithmetic test
Advanced learning of MySQL -- Application -- Introduction
The MySQL team development specifications used by various factories are too detailed. It is recommended to collect them!
MATLB|多微电网及分布式能源交易
STM32 series - serial port UART software pin internal pull-up or external resistance pull-up - cause problem search