章哥:我想做一个HTTP请求过滤的服务,服务人逻辑在test.lua里。
如果本HTTP请求可以通过,用下面的代码把请求转给其他web服务取得结果,然后ngx.print出来:
ngx.location.capture(ngx.var.uri, {host = 'unicorn', args = ngx.req.get_uri_args(), method = ngx.HTTP_POST, body = ngx.encode_args(args)})
如果HTTP请求不可以通过,则ngx.exit(500)
我的问题是:ngx.location.capture时,又被转给自己(test.lua)了,形成了循环调用。
我的nginx.conf如下:
烦请章哥或其他高手看下!worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
lua_shared_dict dict 10m;
server {
listen 80;
server_name localhost;
access_log logs/access.log;
error_log logs/error.log;
location / {
if ($request_method ~* GET) {
proxy_pass http://unicorn;
}
lua_code_cache off;
content_by_lua_file /usr/local/nginx/conf/test.lua;
}
upstream unicorn {
server 10.80.30.32:3000;
}
}