NGiNX-没有为错误(4xx,5xx)和成功(2xx)返回足够的标头 [英] NGiNX - Not returning sufficient headers for error(4xx, 5xx) Vs Success(2xx)
问题描述
你好朋友
Hello Friends,
I have independently ask a question in the same context
but from angular
perspective.
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.
特殊情况是,我无法获得request status
. 例如,如果我的API返回401, 400, 500..
除了200 ,在这种情况下,我的angular
App
将http response-status
作为"零( 0)",无论返回什么服务器.我的主要假设是由于 CORS
问题(主要是所有建议修复的问题)或某些隐藏的问题(对我而言).
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).
在Angular中,我可以看到以下内容(请参见屏幕截图)
我的假设是,如果CORS发出,那么我的200请求响应也必须 不是服务器.所以我的猜测是我已正确配置了CORS.
My assumption is, if CORS issue then my 200 request response must also not server. so my guess is CORS I have configured correctly.
任何高级帮助都将不胜感激!
注意-
- 我感到困惑的是在
NGiNX
方面还是在Angular
方面.这就是为什么我在不同标签(Angular, Nginx
)下问同样的问题. - 我还在服务器端实现了 SSL .所以也请考虑这种情况.
- I am confuse whether it's
NGiNX
side an issue orAngular
side. that's why I ask the same question under different tags(Angular, Nginx
). - I have also implemented SSL at server side. so kindly consider this case as well.
推荐答案
要将标头添加到4xx和5xx错误:在设置标头时,必须使用always
参数:
To add headers to 4xx and 5xx errors: When setting the headers, you must use the always
param:
add_header <header_name> <value> always
请参见 http://nginx.org/en/docs上的文档/http/ngx_http_headers_module.html#add_header :
将指定字段添加到响应头中,条件是响应代码等于200、201(1.3.10),204、206、301、302、303、304、307(1.1.16、1.0.13)或308(1.13.0)…如果指定了
always
参数(1.7.5),则无论响应代码如何,都将添加标头字段.
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.
这篇关于NGiNX-没有为错误(4xx,5xx)和成功(2xx)返回足够的标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!