NGiNX - Not returning sufficient headers for error(4xx, 5xx) Vs Success(2xx)

倾然丶 夕夏残阳落幕 提交于 2020-05-29 11:02:19

问题


Hello Friends,

I have independently ask a question in the same context but from angular perspective.

Kindly refer my NGiNX server configuration .

What I am phasing is, whenever my Angular app's REST request successfully(200) returns from server(where NGiNX installed) in such a case NGiNX returns sufficient headers along with response & I am able to successfully handle it Vs Error request/response.

Especial case is, I am unable to get request status. For example, if my API return 401, 400, 500.. except 200 in such a case my angular App is getting http response-status as a "Zero(0)" irrespective of what server returns. My main assumption is due to either CORS issue(which is mainly all recommending to fix) or some hidden(for me).

In Angular I am able to see below things(refer screen-shot),

My assumption is, if CORS issue then my 200 request response must also not server. so my guess is CORS I have configured correctly.

Any Help would be really appreciate in advanced!

NOTE -

  1. I am confuse whether it's NGiNX side an issue or Angular side. that's why I ask the same question under different tags(Angular, Nginx).
  2. I have also implemented SSL at server side. so kindly consider this case as well.

回答1:


To add headers to 4xx and 5xx errors: When setting the headers, you must use the always param:

add_header <header_name> <value> always

See the docs at http://nginx.org/en/docs/http/ngx_http_headers_module.html#add_header:

Adds the specified field to a response header provided that the response code equals 200, 201 (1.3.10), 204, 206, 301, 302, 303, 304, 307 (1.1.16, 1.0.13), or 308 (1.13.0)… If the always parameter is specified (1.7.5), the header field will be added regardless of the response code.



来源:https://stackoverflow.com/questions/53057967/nginx-not-returning-sufficient-headers-for-error4xx-5xx-vs-success2xx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!