check if error status 502 or 504 generated by upstream or there is a connection error between proxy edge and upstream

36 views
Skip to first unread message

Hadi Abbasi

unread,
May 10, 2020, 11:33:26 AM5/10/20
to openresty-en
Hey guys...

I'm using openresty in my proxy server, and my proxy server receives response data using header and body filter by lua!

some times the response status code is 502 or maybe 504. some times it's generated by upstream and sometimes there is a connection error between my proxy edge server and upstream server!

is there any way to check if the response status code is generated by edge server (openresty) because of connection errors or is generated via upstream like this line in PHP:

header("HTTP/1.1 502 Bad Gateway");

I need to know the source of 502 , 504 connection error in my edge proxy server! (edge or upstream)

thanks a lot...

ecc256

unread,
May 10, 2020, 12:41:51 PM5/10/20
to openresty-en

Hadi,

You can use "Server" header.

And if you allow to pass "Server" header from upstream(s) to the client, you should be able to distinguish between 5XX coming from upstream vs. openresty ones:

proxy_pass_header "Server";

It’ll work if you have multiple proxies staked also.

Just have them set with different "Server" header.

Naturally, any “must be in response” header should do, providing you distinguish them.

"Server" is most convenient one, IMO.

There should be more ways to do it.

Regards,

ecc256

Hadi Abbasi

unread,
May 10, 2020, 3:10:19 PM5/10/20
to openresty-en
thanks a lot ecc256 ,
your message is helpful for me...
good luck...
All The Best,
Hadi

ecc256

unread,
May 10, 2020, 3:38:02 PM5/10/20
to openresty-en
Hadi,
You are welcome! :)

Reply all
Reply to author
Forward
0 new messages