Openrestry处理HTTP请求的执行阶段来自于Nginx,Nginx的HTTP框架依据常见的处理流程将处理阶段划分为11个阶段,其中每个处理阶段可以由任意多个HTTP模块流水式地处理请求,Openresty通过ngx_http_lua_module将Lua特性嵌入Nginx,ngx_http_lua_module属于一个Nginx的HTTP模块,为高性能服务开发封装了7个相应HTTP请求处理阶段如下:
http {
# use sendfile
sendfile on;
# Va initialization
lua_package_path "...;;";
lua_package_cpath "...;";
lua_code_cache off;
init_by_lua_block {ngx.log(ngx.ERR, '=======>init')}
init_worker_by_lua_block {ngx.log(ngx.ERR, '=======>init_worker')}
rewrite_by_lua_block {ngx.log(ngx.ERR, '=======>rewrite')}
access_by_lua_block {ngx.log(ngx.ERR, '=======>access')}
header_filter_by_lua_block {ngx.log(ngx.ERR, '=======>header_filter')}
body_filter_by_lua_block {ngx.log(ngx.ERR, '=======>body_filter')}
log_by_lua_block {ngx.log(ngx.ERR, '=======>log')}
server {
# List port
listen 7200;
set $template_root '';
set_by_lua_block $a {ngx.log(ngx.ERR, '=======>set'); return 'xxx'}
# Access log with buffer, or disable it completetely if unneeded
access_log logs/development-access.log combined buffer=16k;
# access_log off;
# Error log
error_log logs/development-error.log;
# Va runtime
location / {
content_by_lua_block {
ngx.log(ngx.ERR, '=======>content')
ngx.say('----------')
ngx.say('---ccc-------')
ngx.say('---vvvv-------')
ngx.say('---vdddv-------')
ngx.say('---ggvv-------')
}
# content_by_lua_file ./pub/index.lua;
}
}
}
set_by_lua:1: =======>set
rewrite_by_lua(development-nginx.conf:31):1: =======>rewrite
access_by_lua(development-nginx.conf:32):1: =======>access
content_by_lua(development-nginx.conf:60):2: =======>content
header_filter_by_lua:1: =======>header_filter
body_filter_by_lua:1: =======>body_filter
body_filter_by_lua:1: =======>body_filter
body_filter_by_lua:1: =======>body_filter
body_filter_by_lua:1: =======>body_filter
body_filter_by_lua:1: =======>body_filter
body_filter_by_lua:1: =======>body_filter
log_by_lua(development-nginx.conf:35):1: =======>log while logging request