当前位置:网站首页>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"
}
边栏推荐
- 丸子百度小程序详细配置教程,审核通过。
- Codeforces Round #770 (Div. 2) ABC
- One plus six brushes into Kali nethunter
- Advanced learning of MySQL -- Application -- Introduction
- Visual explanation of Newton iteration method
- Grpc message sending of vertx
- 使用druid連接MySQL數據庫報類型錯誤
- Restful fast request 2022.2.1 release, support curl import
- Erreur de type de datagramme MySQL en utilisant Druid
- STL container
猜你喜欢

What sparks can applet container technology collide with IOT

Write a thread pool by hand, and take you to learn the implementation principle of ThreadPoolExecutor thread pool

"2022" is a must know web security interview question for job hopping

How to make a cool ink screen electronic clock?

CAM Pytorch

Runc hang causes the kubernetes node notready
![[OpenGL learning notes 8] texture](/img/77/a4a784a535ea6f4c2382857b266cec.jpg)
[OpenGL learning notes 8] texture

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!

Codeforces Global Round 19 ABC

The MySQL team development specifications used by various factories are too detailed. It is recommended to collect them!
随机推荐
STL container
Exploration of short text analysis in the field of medical and health (I)
The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety
Outlook:总是提示输入用户密码
Stored procedure and stored function in Oracle
A tab Sina navigation bar
Introduce reflow & repaint, and how to optimize it?
[Yu Yue education] National Open University spring 2019 0505-22t basic nursing reference questions
The most powerful new household god card of Bank of communications. Apply to earn 2100 yuan. Hurry up if you haven't applied!
Exploration of short text analysis in the field of medical and health (II)
The MySQL team development specifications used by various factories are too detailed. It is recommended to collect them!
Application and Optimization Practice of redis in vivo push platform
PowerShell:在代理服务器后面使用 PowerShell
Video display and hiding of imitation tudou.com
Numpy library introductory tutorial: basic knowledge summary
. Net starts again happy 20th birthday
Common bit operation skills of C speech
Win:将一般用户添加到 Local Admins 组中
Yyds dry inventory swagger positioning problem ⽅ formula
Practical case of SQL optimization: speed up your database