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

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

问题描述

你好朋友

Hello Friends,

我已经独立地问过

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

请参考我的NGiNX服务器我要使用的是,每当我的Angular应用程序的REST请求成功( 200 )从服务器(安装了NGiNX /em>)在这种情况下NGiNX返回sufficient headers以及response&我能够成功处理 VS 错误请求/响应.

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 Apphttp 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.

任何高级帮助都将不胜感激!

注意-

  1. 我感到困惑的是在NGiNX方面还是在Angular方面.这就是为什么我在不同标签(Angular, Nginx)下问同样的问题.
  2. 我还在服务器端实现了 SSL .所以也请考虑这种情况.
  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.

推荐答案

要将标头添加到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屋!

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