[alibaba/tengine]tengine不能正常返回后端的response

2023-12-21 856 views
3

proxy_intercept_errors on ;这个配置在tengine不生效 导致无法获取后端500错误码中的response,自动返回的500的错误页 通过获取resp_body发现,tengine确实收到了后端的response 同样的配置在nginx上是可以正常返回 tengine版本 Tengine version: Tengine/2.3.2 nginx version: nginx/1.17.3

debug日志如下

2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http keepalive handler
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 malloc: 00007F201C9C6000:524288
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 recv: eof:0, avail:1
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 recv: fd:39 1109 of 524288
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 reusable connection: 0
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 posix_memalign: 00007F201DF26000:4096 @16
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http header: "Host: 192.168.1.100"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http header: "Connection: keep-alive"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http header: "Content-Length: 345"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http header: "Accept: application/json, text/javascript, */*; q=0.01"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http header: "X-Gw-Access-Token: 08feee93-e272-4231-bfa6-be1f9078f1146"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http header: "X-Requested-With: XMLHttpRequest"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http header: "csrfcheck: dc9cb14b-047e-4b30-8dd9-dadff46e12ed6"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http header: "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http header: "Content-Type: application/json;charset=UTF-8"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http header: "Origin: http://192.168.1.100"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http header: "Referer: http://192.168.1.100/tradePasswordEdit.html?&fund_trade_account=00305011XH&salesorg_id=325&X-Gw-Access-Token=123"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http header: "Accept-Encoding: gzip, deflate"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http header: "Accept-Language: zh-CN,zh;q=0.9"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http header done
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 generic phase: 0
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 generic phase: 1
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 rewrite phase: 2
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 test location: "/"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 using configuration "/"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http cl:345 max:524288000
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 rewrite phase: 4
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 rewrite phase: 5
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 post rewrite phase: 6
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 generic phase: 7
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 generic phase: 8
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 generic phase: 9
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http vts limit handler
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 generic phase: 10
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 generic phase: 11
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 generic phase: 12
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 access phase: 13
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 vts set filter variables
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 access phase: 14
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 access phase: 15
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 access phase: 16
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 post access phase: 17
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 generic phase: 18
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 generic phase: 19
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http client request body preread 345
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http request body content length filter
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http body new buf t:1 f:0 00007F201C9C62FC, pos 00007F201C9C62FC, size: 345 file: 0, size: 0
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http dummy input body filter
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http init upstream, client timer: 0
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 posix_memalign: 00007F201D190000:4096 @16
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http script copy: "Host"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http script var: "192.168.1.100"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http script copy: "X-Real-IP"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http script var: "2.0.4.22"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http script copy: "X-Forwarded-For"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http script var: "2.0.4.22"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http script copy: "X-Forwarded-Proto"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http script var: "http"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http script copy: "Connection"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http script copy: "close"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http script copy: "Content-Length"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http script var: "345"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http script copy: ""
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http proxy header: "Accept: application/json, text/javascript, */*; q=0.01"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http proxy header: "X-Gw-Access-Token: 08feee93-e272-4231-bfa6-be1f9078f1146"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http proxy header: "X-Requested-With: XMLHttpRequest"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http proxy header: "csrfcheck: dc9cb14b-047e-4b30-8dd9-dadff46e12ed6"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http proxy header: "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http proxy header: "Content-Type: application/json;charset=UTF-8"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http proxy header: "Origin: http://192.168.1.100"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http proxy header: "Referer: http://192.168.1.100/tradePasswordEdit.html?&fund_trade_account=00305011XH&salesorg_id=325&X-Gw-Access-Token=123"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http proxy header: "Accept-Encoding: gzip, deflate"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http proxy header: "Accept-Language: zh-CN,zh;q=0.9"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http proxy header:
"POST /am4-cloud/am4-bgb-service-manage/1.0/updatePassWordV2 HTTP/1.1
Host: 192.168.1.100
X-Real-IP: 2.0.4.22
X-Forwarded-For: 2.0.4.22
X-Forwarded-Proto: http
Connection: close
Content-Length: 345
Accept: application/json, text/javascript, */*; q=0.01
X-Gw-Access-Token: 08feee93-e272-4231-bfa6-be1f9078f1146
X-Requested-With: XMLHttpRequest
csrfcheck: dc9cb14b-047e-4b30-8dd9-dadff46e12ed6
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36
Content-Type: application/json;charset=UTF-8
Origin: http://192.168.1.100
Referer: http://192.168.1.100/tradePasswordEdit.html?&fund_trade_account=00305011XH&salesorg_id=325&X-Gw-Access-Token=123
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9

"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http cleanup add: 00007F201CB8BDC0
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 init keepalive peer
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 get keepalive peer
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 get rr peer, try: 1
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 stream socket 18
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 epoll add connection: fd:18 ev:80002005
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 connect to 10.100.42.59:8087, fd:18 #490848685
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http upstream connect: -2
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 posix_memalign: 00007F201FAF1200:144 @16
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 event timer add: 18: 60000:38058801158
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http finalize request: -4, "/am4-cloud/am4-bgb-service-manage/1.0/updatePassWordV2?" a:1, c:2
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http request count:2 blk:0
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http run request: "/am4-cloud/am4-bgb-service-manage/1.0/updatePassWordV2?"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http request empty handler
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http upstream request: "/am4-cloud/am4-bgb-service-manage/1.0/updatePassWordV2?"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http upstream send request handler
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http upstream send request
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http upstream send request body
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 chain writer buf fl:0 s:832
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 chain writer buf fl:1 s:345
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 chain writer in: 00007F201CB8BE78
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 writev: 1177 of 1177
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 chain writer out: 0000000000000000
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 event timer del: 18: 38058801158
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 event timer add: 18: 60000:38058801158
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http upstream request: "/am4-cloud/am4-bgb-service-manage/1.0/updatePassWordV2?"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http upstream process header
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 malloc: 00007F201D1F0000:65536
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 recv: eof:0, avail:1
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 recv: fd:18 522 of 65536
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http proxy status 500 "500 Internal Server Error"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http proxy header: "Server: hsiar"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http proxy header: "Date: Thu, 20 Oct 2022 01:14:41 GMT"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http proxy header: "Content-Type: application/json;charset=utf-8"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http proxy header: "Content-Length: 129"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http proxy header: "Connection: close"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http proxy header: "Content-Language: zh-CN,zh;q=0.9"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http proxy header: "Access-Control-Allow-Methods: GET,POST"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http proxy header: "Access-Control-Allow-Credentials: true"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http proxy header: "Access-Control-Expose-Headers: x-msg-timeout,X-Msg-Trace,csrfcheck,ShardingInfo,Partition,Date,Server"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http proxy header done
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 lua capture header filter, uri "/am4-cloud/am4-bgb-service-manage/1.0/updatePassWordV2"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 HTTP/1.1 500 Internal Server Error
Server: Tengine
Date: Thu, 20 Oct 2022 01:14:31 GMT
Content-Type: application/json;charset=utf-8
Content-Length: 129
Connection: keep-alive
Content-Language: zh-CN,zh;q=0.9
Access-Control-Allow-Methods: GET,POST
Access-Control-Allow-Credentials: true
Access-Control-Expose-Headers: x-msg-timeout,X-Msg-Trace,csrfcheck,ShardingInfo,Partition,Date,Server

2022/10/20 09:14:31 [debug] 23851#23851: *490819062 write new buf t:1 f:0 00007F201D1907F0, pos 00007F201D1907F0, size: 400 file: 0, size: 0
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http write filter: l:0 f:0 s:400
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http cacheable: 0
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http proxy filter init s:500 h:0 c:0 l:129
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http upstream process upstream
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 pipe read upstream: 0
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 pipe preread: 129
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 pipe buf free s:0 t:1 f:0 00007F201D1F0000, pos 00007F201D1F0189, size: 129 file: 0, size: 0
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 pipe length: 129
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 input buf #0
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 pipe write downstream: 1
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 pipe write downstream flush in
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http output filter "/am4-cloud/am4-bgb-service-manage/1.0/updatePassWordV2?"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http copy filter: "/am4-cloud/am4-bgb-service-manage/1.0/updatePassWordV2?"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 lua capture body filter, uri "/am4-cloud/am4-bgb-service-manage/1.0/updatePassWordV2"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http trim filter
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http footer body filter
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http postpone filter "/am4-cloud/am4-bgb-service-manage/1.0/updatePassWordV2?" 00007F201CB8BE88
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 write old buf t:1 f:0 00007F201D1907F0, pos 00007F201D1907F0, size: 400 file: 0, size: 0
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 write new buf t:1 f:0 00007F201D1F0000, pos 00007F201D1F0189, size: 129 file: 0, size: 0
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http write filter: l:0 f:0 s:529
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http copy filter: 0 "/am4-cloud/am4-bgb-service-manage/1.0/updatePassWordV2?"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 pipe write downstream done
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 event timer: 18, old: 38058801158, new: 38058801166
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http upstream exit: 0000000000000000
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 finalize http upstream request: 0
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 finalize http proxy request
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 free keepalive peer
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 free rr peer 1 0
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 close http upstream connection: 18
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 free: 00007F201FAF1200, unused: 48
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 event timer del: 18: 38058801158
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 reusable connection: 0
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http upstream temp fd: -1
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http output filter "/am4-cloud/am4-bgb-service-manage/1.0/updatePassWordV2?"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http copy filter: "/am4-cloud/am4-bgb-service-manage/1.0/updatePassWordV2?"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 lua capture body filter, uri "/am4-cloud/am4-bgb-service-manage/1.0/updatePassWordV2"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http trim filter
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http footer body filter
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http postpone filter "/am4-cloud/am4-bgb-service-manage/1.0/updatePassWordV2?" 00007FFE6E9D3050
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 write old buf t:1 f:0 00007F201D1907F0, pos 00007F201D1907F0, size: 400 file: 0, size: 0
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 write old buf t:1 f:0 00007F201D1F0000, pos 00007F201D1F0189, size: 129 file: 0, size: 0
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 write new buf t:0 f:0 0000000000000000, pos 0000000000000000, size: 0 file: 0, size: 0
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http write filter: l:1 f:0 s:529
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http write filter limit 1048576
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 writev: 529 of 529
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http write filter 0000000000000000
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http copy filter: 0 "/am4-cloud/am4-bgb-service-manage/1.0/updatePassWordV2?"
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http finalize request: 0, "/am4-cloud/am4-bgb-service-manage/1.0/updatePassWordV2?" a:1, c:1
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 set http keepalive handler
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http close request
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http log handler
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http status: request_time 8
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 http vts handler
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 free: 00007F201D1F0000
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 free: 00007F201DF26000, unused: 4
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 free: 00007F201CB8B000, unused: 4
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 free: 00007F201D190000, unused: 167
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 free: 00007F201C9C6000
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 hc free: 0000000000000000
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 hc busy: 0000000000000000 0
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 reusable connection: 1
2022/10/20 09:14:31 [debug] 23851#23851: *490819062 event timer add: 39: 500000:38059241166

回答

1

你确定 nginx 和 tengine验证时的配置是一样的?

tengine 自定义body的模块没有开源 所以行为与nginx core是一致的

在 proxy_intercept_errors off; 时 网关不拦截 透传后端应用侧的error body

在 proxy_intercept_errors on;时 网关拦截300+ status code,如果不存在error_page,则仍然透传后端应用侧的error body;如果存在error_page,则使用自定义的error page替换后端的error body。

基于最新的release版本
image