OpenResty
OpenResty 就是 Nginx + Lua
中文官网 https://openresty.org/cn/
GitHub https://github.com/openresty/openresty
Components https://openresty.org/cn/components.html
lua-nginx-module
openresty/lua-nginx-module https://github.com/openresty/lua-nginx-module
access_by_lua_block
https://github.com/openresty/lua-nginx-module#access_by_lua_block
syntax: access_by_lua_block { lua-script } context: http, server, location, location if phase: access tail
例如,加载 lua 脚本,处理请求,并验证签名
location ~^/api/user/ {
access_by_lua_block {
local req_processor = require("lua/req_processor")
req_processor.set_req_id()
req_processor.set_real_ip()
local sign = require("lua/verify_sign")
sign.verify_sign()
}
proxy_pass http://localhost:8001;
add_header 'Access-Control-Allow-Origin' $corsHost;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}