C# ASP.NETCore2.2通过NGINX部署在Linux上,POST请求返回HTTP错误400

C# ASP.NETCore2.2通过NGINX部署在Linux上,POST请求返回HTTP错误400,c#,asp.net,linux,nginx,C#,Asp.net,Linux,Nginx,我正在部署一个简单的asp.net核心应用程序,它只使用主控制器和单个post方法。我们有两个内部网络,一个是Windows机器,另一个是Linux机器。asp核心应用程序已通过NGINX在linux端部署。为了澄清,我可以通过Linux登录节点的IP地址10.10.40.50:8081作为URL从窗口侧查看网站。要在承载该站点的机器上从Linux端查看该站点,只需使用localhost:5000即可 post方法只接受单个输入,并将相应的pdf文件返回到输入,如下所示: [HttpPost]

我正在部署一个简单的asp.net核心应用程序,它只使用主控制器和单个post方法。我们有两个内部网络,一个是Windows机器,另一个是Linux机器。asp核心应用程序已通过NGINX在linux端部署。为了澄清,我可以通过Linux登录节点的IP地址10.10.40.50:8081作为URL从窗口侧查看网站。要在承载该站点的机器上从Linux端查看该站点,只需使用localhost:5000即可

post方法只接受单个输入,并将相应的pdf文件返回到输入,如下所示:

[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create(string label) {
            if (ModelState.IsValid && label.Length > 0) {
                string newLabel = label.Trim().Split(' ')[0].ToUpper();
                if (fstickChecker.Contains(newLabel )) {
                    var pdf = await CreatePDF(newLabel);
                    return pdf;
                }
                else {
                    return RedirectToAction("Index", new RouteValueDictionary(new { action = "Index", err = "Invalid label selected" }));
                }
            }
            return View();
        }
NGINX站点可用文件(我认为问题可能来自于此)是:

我发现了一些相关的stackoverflow问题,但没有一个能够解决我的问题。 和

我最终将“创建”的POST请求更改为GET,从而解决了问题。不太理想,但就我的情况而言,我可以侥幸逃脱。

只是状态代码没有足够的信息,请检查nginx日志并将日志添加到你的应用程序中(如果还没有)。只要路由在nginx站点可用文件中,是否有任何不适合post方法的地方?将/Home/Create添加到URL时,网站将中断。
 <form method="post" action="/Home/Create">
                        @Html.AntiForgeryToken()
                        <input size="60" type="text" name="label" class="form-control" id="labeler" placeholder="Enter Label" style="float:left;">
                        <div class="rotator-buttons" style="padding-top:45px;">
                            <button type="submit" class=" btn btn-01 t-white" style="float:left; height:40px;width:140px;background-color:#706552">Create PDF</button>
                        </div>
                    </form>
public class Program {
        public static void Main(string[] args) {
            CreateWebHostBuilder(args).Build().Run();
        }

        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>();
    }
public void Configure(IApplicationBuilder app, IHostingEnvironment env) {
        app.UseStaticFiles();
            if (env.IsDevelopment()) {
                app.UseDeveloperExceptionPage();
            }
            else {
                app.UseExceptionHandler("/Home/Error");
            }


            //app.UseCookiePolicy();

            app.UseMvc(routes => {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

# Default server configuration
#
server {
        listen 8081 default_server;
        listen [::]:8081 default_server;

        # SSL configuration
        #
        # listen 443 ssl default_server;
        # listen [::]:443 ssl default_server;
        #
        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
        #
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See: https://bugs.debian.org/765782
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;

        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                #try_files $uri $uri/ =404;
                proxy_pass http://localhost:5000/;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                #proxy_set_header Connection 'upgrade';
                proxy_set_header Connection $http_connection;
                proxy_set_header Host $host;
                proxy_cache_bypass $http_upgrade;
        }

        location /Home/ {
                proxy_pass http://localhost:5000/;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection $http_connection;
                #proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
                proxy_cache_bypass $http_upgrade;
        }


        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #       include snippets/fastcgi-php.conf;
        #
        #       # With php7.0-cgi alone:
        #       fastcgi_pass 127.0.0.1:9000;
        #       # With php7.0-fpm:
        #       fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #       deny all;
        #}
}