NGiNX - 没有为错误(4xx,5xx)与成功(2xx)返回足够的标头 [英] NGiNX - Not returning sufficient headers for error(4xx, 5xx) Vs Success(2xx)

查看:52
本文介绍了NGiNX - 没有为错误(4xx,5xx)与成功(2xx)返回足够的标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友

我已经独立询问

<块引用>

我的假设是,如果 CORS 问题,那么我的 200 请求响应也必须不是服务器.所以我的猜测是我配置正确的 CORS.

任何帮助都将非常感谢!

注意 -

  1. 我很困惑是 NGiNX 方面的问题还是 Angular 方面的问题.这就是为什么我在不同的标签(Angular、Nginx)下问同样的问题.
  2. 我还在服务器端实施了 SSL.所以也请考虑这个案例.

解决方案

要将标题添加到 4xx 和 5xx 错误:设置标题时,必须使用 always 参数:

add_header <价值>总是

请参阅 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),则无论响应代码如何,都会添加标头字段.

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.

解决方案

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.

这篇关于NGiNX - 没有为错误(4xx,5xx)与成功(2xx)返回足够的标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆