首页 > 解决方案 > Nginx Proxy POST fails GET is successful

问题描述

I have nginx running as a proxy in front of a .net core application. The web page is being served correctly and all GET requests work fine. However, all of the POST requests fail with a 404.

Config:

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';
}

Error Log:

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"

What am I doing wrong?

标签: nginxreverse-proxynginx-reverse-proxy

解决方案


The solution was to either clear the Connection header, or set it to 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';
}

推荐阅读