node.js Azure Web 应用程序 returns 长 URL 400
node.js Azure Web App returns 400 on long urls
我在 Azure Web 应用程序中托管 node.js 应用程序。这很好用,除非服务器总是 returns HTTP 400 如果请求太长(即长 URL 或许多 headers。)
似乎错误是Kestrel网关没有到达我的应用程序就返回了,如果请求的长度超过2581字节就会出现这种情况。在本地运行时不会出现同样的问题。这是一个GET请求,URL长还是有长header都没有区别。
我的申请只是returns当前时间:
// Module dependencies
let http = require('http');
http.createServer(function (request, response) {
console.log('request ', request.url);
response.write("Request served at " + new Date().toISOString());
response.end();
}).listen(80);
如果我请求 GET /anything
,响应是符合预期的。但是,如果我执行 GET /{any_very_long_path}
(或包含具有长值的 header),它会失败。
为什么 Azure 会这样限制请求长度?托管 ASP.NET 应用程序时不会发生同样的问题。
If I request GET
/anything
the response is as expected.
However if I do GET
/{any_very_long_path}
(or include a header with a long value)
it fails.
我认为问题与 this issue @ GitHub 有关,
它提到:
On our website, we have pretty big cookies in some scenarios (it might
not be good indeed) and we have been facing many 400 http errors since
yesterday.
这是因为存在 8KB
hard-coded (HTTP_MAX_HEADER_SIZE
) 限制,任何更大的限制 returns 错误代码 400
...
Nodejs Documentation : http.maxHeaderSize
Read-only property specifying the maximum allowed size of HTTP headers
in bytes. Defaults to 8KB. Configurable using the
--max-http-header-size
CLI option.
解决方案:
您可以尝试使用文档中提到的 --max-http-header-size
CLI 选项。
请记住,如果您使用的是反向代理 in-between(例如 NGINX),您还必须增加最大 header 大小...
我在 Azure Web 应用程序中托管 node.js 应用程序。这很好用,除非服务器总是 returns HTTP 400 如果请求太长(即长 URL 或许多 headers。)
似乎错误是Kestrel网关没有到达我的应用程序就返回了,如果请求的长度超过2581字节就会出现这种情况。在本地运行时不会出现同样的问题。这是一个GET请求,URL长还是有长header都没有区别。
我的申请只是returns当前时间:
// Module dependencies
let http = require('http');
http.createServer(function (request, response) {
console.log('request ', request.url);
response.write("Request served at " + new Date().toISOString());
response.end();
}).listen(80);
如果我请求 GET /anything
,响应是符合预期的。但是,如果我执行 GET /{any_very_long_path}
(或包含具有长值的 header),它会失败。
为什么 Azure 会这样限制请求长度?托管 ASP.NET 应用程序时不会发生同样的问题。
If I request
GET
/anything
the response is as expected.However if I do
GET
/{any_very_long_path}
(or include a header with a long value) it fails.
我认为问题与 this issue @ GitHub 有关, 它提到:
On our website, we have pretty big cookies in some scenarios (it might not be good indeed) and we have been facing many 400 http errors since yesterday.
这是因为存在 8KB
hard-coded (HTTP_MAX_HEADER_SIZE
) 限制,任何更大的限制 returns 错误代码 400
...
Nodejs Documentation : http.maxHeaderSize
Read-only property specifying the maximum allowed size of HTTP headers in bytes. Defaults to 8KB. Configurable using the
--max-http-header-size
CLI option.
解决方案:
您可以尝试使用文档中提到的 --max-http-header-size
CLI 选项。
请记住,如果您使用的是反向代理 in-between(例如 NGINX),您还必须增加最大 header 大小...