小编Aar*_*ron的帖子

Kubernetes Nginx入口控制器返回502,但仅用于AJAX / XmlHttpRequest请求

我有一个在nginx入口控制器后面运行Kubernetes的Web应用程序,它可以很好地用于请求浏览,但是来自浏览器的任何AJAX / XMLHTTPRequest都会从nginx收到502错误。

我捕获了常规和AJAX请求的HTTP标头,它们看起来都不错,正确的Host标头,协议等。我感到困惑,为什么只有XMLHttpRequest请求从nginx获取502。没有延迟/挂起,502是即时的。这些请求似乎永远不会到达应用程序,但会被nginx本身拒绝。将nginx切换为直接负载均衡器,问题就消失了。

我将进一步进行挖掘,但我想知道是否其他任何使用Nginx Ingress控制器的人之前都曾见过此问题并已解决?

我从nginx日志中选择了此错误,这表明容器对于nginx缓冲区返回的标头过大。但是我检查了nginx.conf并禁用了缓冲:'proxy_buffering off;'

2016/10/27 19:55:51 [error] 309#309: *43363 upstream sent too big header while reading response header from upstream, client: 10.20.51.1, server: foo.example.com, request: "GET /admin/pages/listview HTTP/2.0", upstream: "http://10.20.66.97:80/admin/pages/listview", host: "foo.example.com", referrer: "https://foo.example.com/admin/pages"
Run Code Online (Sandbox Code Playgroud)

奇怪的是,仅当XmlHttpRequest请求URL时,您才收到504错误。如果我使用curl请求相同的URL,它可以正常工作,并且响应标头如下。相同URL的AJAX / XmlHttpRequest会使响应头太大吗?

HTTP/1.1 200 OK
Server: nginx/1.11.3
Date: Thu, 27 Oct 2016 20:15:16 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 6596
Connection: keep-alive
X-Frame-Options: SAMEORIGIN
X-Powered-By: PHP/5.5.9-1ubuntu4.19
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: max-age=0, must-revalidate, no-transform, no-cache, no-store
Pragma: no-cache
X-Controller: …
Run Code Online (Sandbox Code Playgroud)

nginx kubernetes

0
推荐指数
1
解决办法
2240
查看次数

标签 统计

kubernetes ×1

nginx ×1