nginx version: openresty/1.9.7.1
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-cc-opt=-O2 --add-module=../ngx_devel_kit-0.2.19 --add-module=../echo-nginx-module-0.58 --add-module=../xss-nginx-module-0.05 --add-module=../ngx_coolkit-0.2rc3 --add-module=../set-misc-nginx-module-0.29 --add-module=../form-input-nginx-module-0.11 --add-module=../encrypted-session-nginx-module-0.04 --add-module=../srcache-nginx-module-0.30 --add-module=../ngx_lua-0.9.20 --add-module=../ngx_lua_upstream-0.04 --add-module=../headers-more-nginx-module-0.29 --add-module=../array-var-nginx-module-0.04 --add-module=../memc-nginx-module-0.16 --add-module=../redis2-nginx-module-0.12 --add-module=../redis-nginx-module-0.3.7 --add-module=../rds-json-nginx-module-0.14 --add-module=../rds-csv-nginx-module-0.07 --with-ld-opt=-Wl,-rpath,/usr/local/luajit/lib --with-http_ssl_module
默认配置下加入location:
location ^~ /test/ {
rewrite_by_lua_block {
ngx.log(ngx.ALERT, 'rewrite')
}
access_by_lua_block {
ngx.log(ngx.ALERT, 'access')
}
#并没有哪个程序监听这个端口
proxy_pass http://127.0.0.1:65535;
header_filter_by_lua_block {
ngx.log(ngx.ALERT, 'header_filter')
}
body_filter_by_lua_block {
ngx.log(ngx.ALERT, 'body_filter')
}
log_by_lua_block {
ngx.log(ngx.ALERT, 'log')
}
}
此时访问http://localhost/test/,可在error观察到如下日志:
2016/01/22 14:03:22 [alert] 3148#0: *1 [lua] rewrite_by_lua(nginx.conf:20):2: rewrite, client: 127.0.0.1, server: localhost, request: "GET /test/ HTTP/1.1", host: "localhost"
2016/01/22 14:03:22 [alert] 3148#0: *1 [lua] access_by_lua(nginx.conf:23):2: access, client: 127.0.0.1, server: localhost, request: "GET /test/ HTTP/1.1", host: "localhost"
2016/01/22 14:03:22 [error] 3148#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "GET /test/ HTTP/1.1", upstream: "http://127.0.0.1:65535/test/", host: "localhost"
在 2016年1月22日星期五 UTC+8下午12:47:31,agentzh写道:
Hello!
2016-01-21 18:11 GMT-08:00 xiaooloong:
> proxy_pass 到后端,当后端失败,nginx 直接返回 5xx错误
>
> 同一个location内定义的
> header_filter_by_lua
> body_filter_by_lua
> log_by_lua
> 均不会被执行,求解
>
请提供一个最小化的完整示例以便我们可以复现问题。另外,临时开启 nginx 调试日志可以得到更多信息,见
http://nginx.org/en/docs/debugging_log.html
同时的操作步骤也适用于 OpenResty.
Regards,
-agentzh