ubuntu - DotNet Core 应用程序不接受 Linux 上的 POST

标签 ubuntu nginx asp.net-core asp.net-core-2.0

这是我的第一个 DotNetCore 2.0 应用程序,我想用它来比较 IIS/Windows 和 nginx/Ubuntu 之间的性能。它是一个与许多服务(mongo/redis/session state)对话以创建虚假但真实的用户旅程的应用程序。

当从 Visual Studio 调试或从 PostMan 调用时,该应用程序在 Windows 上运行得非常好,但是,如果我部署到 Ubuntu,尽管我可以尽快访问该网站的首页和下一页(均为 GET)当我将表单发布到第二页(仅一个字段)时,浏览器和 postman 失败,返回 400,但没有详细信息。 Ubuntu 不会记录除 Web 服务器启动以外的任何内容,尽管它之前已经记录了错误,因此日志记录正在工作。

我什至尝试了 IgnoreAntiforgeryToken 操作,但没有帮助。

相关配置:

public void ConfigureServices(IServiceCollection services)
{
    if (Configuration.GetValue<bool>("useFileSystem"))
    {
        services.AddDataProtection()
            .PersistKeysToFileSystem(new DirectoryInfo(Configuration.GetValue<string>("fileSystemPersistPath")))
            .SetApplicationName("Perftest2018");
    }
    else
    {
        services.AddDataProtection()
            .SetApplicationName("Perftest2018");
    }

    services.AddMvc();
    services.AddDistributedMemoryCache();
    services.AddSession(options =>
    {
        options.IdleTimeout = TimeSpan.FromSeconds(30);
        options.Cookie.HttpOnly = true;
    });

    services.Configure<IISOptions>(options =>
    {
        options.AutomaticAuthentication = false;
    });

    //<snip> the rest of my services
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    app.UseDeveloperExceptionPage();
    app.UseStaticFiles();
    app.UseSession();

    app.UseForwardedHeaders(new ForwardedHeadersOptions
    {
        ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
    });

    app.UseMvc(routes =>
    {
        routes.MapRoute(name: "default",template: "{controller=Home}/{action=Index}/{id?}");
    });
}

Action 是这样的:

[HttpPost]
public async Task<IActionResult> Authorize(AuthorizeViewModel model)
{
    // The view model just has a single string property with no other attributes
}

最佳答案

这是由代理中的额外 nginx header 引起的,这些 header 是从另一台运行 TLS 的服务器获取的。 header Upgrade $http_upgradeConnection "upgrade" 可能不允许 POST!

关于ubuntu - DotNet Core 应用程序不接受 Linux 上的 POST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48708077/

相关文章:

tomcat 8在处理get请求时抛出400错误

ssl - 如何通过两个服务器 nginx 传递客户端证书?

c# - Entity Framework Core 在 sleep 状态下留下许多连接

asp.net-core - appsettings.json 文件不在 .net 核心控制台项目中

python - 将以前的 Python 输出恢复到终端

Ubuntu apt-get 从不存在的文件安装错误

ubuntu - 如何覆盖 dpkg-buildflags CFLAGS?

r - 安装 R 包 Ubuntu 22.04.1 LTE 时的包 libcurl4-openssl-dev 问题

python - 使用 nginx 作为反向代理将 http 路由到 https

asp.net-core - 在 ASP.NET Core 中将 html 导出为 pdf