Nginx Proxy POST 失败 GET 成功

Nginx Proxy POST fails GET is successful

我有 nginx 运行 作为 .net 核心应用程序前面的代理。网页被正确提供,所有 GET 请求都正常工作。但是,所有 POST 请求都以 404 失败。

配置:

location ~ / {
  proxy_pass        http://127.0.0.1:5000;

  proxy_http_version 1.1;
  proxy_set_header Upgrade $http_upgrade;
  proxy_set_header Connection "upgrade";

  client_max_body_size 15M;

  more_clear_input_headers 'Accept-Encoding';
}

错误日志:

111.111.111.111 - - [25/Feb/2020:19:56:37 +0000] "GET /Content/favicon.png HTTP/2.0" 200 1003 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:73.0) Gecko/20100101 Firefox/73.0"
111.111.111.111 - - [25/Feb/2020:19:56:51 +0000] "POST /api/encode/ASCII/dGVzdA== HTTP/2.0" 400 463 "https://example.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:73.0) Gecko/20100101 Firefox/73.0"

我做错了什么?

解决方案是清除 Connection header,或将其设置为 keep-alive

location ~ / {
  proxy_pass        http://127.0.0.1:5000;

  proxy_http_version 1.1;
  proxy_set_header Upgrade $http_upgrade;
  proxy_set_header Connection 'keep-alive';

  client_max_body_size 15M;

  more_clear_input_headers 'Accept-Encoding';
}