default_type application/octet-stream; include/usr/local/openresty/nginx/conf/mime.types; rewrite_by_lua_block{ ngx.log(ngx.ALERT,"(http | rewrite_by)新请求接入,是否内部重定向:"..tostring(ngx.req.is_internal())) } access_by_lua_block{ ngx.log(ngx.ALERT,"(http | access_by)新请求接入...
Lua VM 会将require进来的模块换成到package.loadedtable 里,模块里的变量都会被缓存起来,在同一个 Lua VM下,模块中的变量在每个请求中是共享的,这样就可以避免使用全局变量来实现共享了,看下面一个例子: nginx.conf worker_processes 1; ... location { ... lua_code_cache on; default_type "text/html";...
在server模块加上 location /helloworld { default_type text/html; content_by_lua 'ngx.say("hello world")'; } 检查配置文件是否正确 # /usr/local/openresty/nginx/sbin/nginx -t -c /usr/local/openresty/nginx/conf/nginx.conf 重启nginx # ./nginx -s reload 访问http://10.11.0.215/helloworld 输...
location /goods-center/getGoodsDetails { default_type application/json; content_by_lua_file lua/item.lua; } 1. 2. 3. 4. 然后在/usr/local/openresty/nginx/lua 目录中创建item.lua,添加下面lua代码 local args = ngx.req.get_uri_args() ngx.say(args["goodsId"]) 1. 2. 3. 重新加载nginx...
# 使用default_type来确定MIME的类型 default_type 'text/plain'; content_by_lua_block { local res = ngx.location.capture("/some_other_location") if res then ngx.say("status:",res.status) ngx.say("body:") ngx.print(res.body) end ...
worker_processes1;events{worker_connections1024;}http{include mime.types;default_type application/octet-stream;sendfile on;keepalive_timeout65;server{listen80;server_name localhost;location/{root html;index index.html index.htm;}error_page500502503504/50x.html;location=/50x.html{root html;}}} ...
location/test{default_type text/html;content_by_lua'ngx.say("hello openresty")';}# 重启Nginx $/usr/local/openresty/nginx/sbin/nginx-s reload # 浏览器访问127.0.0.1/test content_by_lua_file 代码语言:javascript 复制 $ vim nginx.conf
default_type "text/html"; #nginx使用 lua脚本进行 内容处理 content_by_lua_file /usr/example/lua/test_request.lua; #内容体处理完成后调用 echo_after_body "ngx.var.b $b"; echo_after_body "http_host $c"; } 1. 2. 3. 4. 5.
worker_processes 1; # 设置错误日志文件路径 error_log logs/error.log; # 配置Nginx服务器与用户的网络连接 events{ # 设置每个工作进程的最大连接数 worker_connections 10224; } http{ # 虚拟机主机块定义 server{ # 监听端口 listen 8001; # 配置请求的路由 location /{ default_type text/htm...
server { listen 80; server_name localhost; location /lua { default_type text/html; content_by_lua_file lua/hello.lua; } } 关闭缓存,开启热部署 nginx+lua开发时因为已经加载进内存,修改lua脚本不会起作用,这样不方便调试。nginx配置中将lua_code_cache配置成on/off来控制是否关闭lua 的cache缓存,如果设...