这是我的第一个 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_upgrade
和 Connection "upgrade"
可能不允许 POST!
关于ubuntu - DotNet Core 应用程序不接受 Linux 上的 POST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48708077/