.net核心nginx托管套接字不允许http发布 [英] .net core nginx hosting sockets doesn't allow http post

查看:82
本文介绍了.net核心nginx托管套接字不允许http发布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试建立一个具有http功能(包括http post功能)和Web套接字(例如signalR)的网站.我正在尝试使用nginx将这个网站托管在ubuntu服务器上.通常,在nginx上的设置是这样的:

I am trying to make a website that would have http functions including http post functions, and also web sockets (such as signalR). I am trying to host this website on an ubuntu server using nginx. Generally the set up is something like this on nginx:

server {
 listen 80;
 location / {
    proxy_pass http://localhost:5000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection keep-alive;
    proxy_set_header Host $http_host;
    proxy_cache_bypass $http_upgrade;
 }
}

但是,我后来发现我需要添加proxy_set_header Connection "upgrade";才能使用websockets.但是,在.net核心项目中添加此行会导致所有http帖子请求显示400错误,如下所示

However, I later found that I need to add proxy_set_header Connection "upgrade"; in order to use websockets. However, adding this line in a .net core project results in all http post requests showing a 400 error as shown here 400 status error when posting form data in ASP.Net Core. Is there a set up that would allow both posts and web sockets?

推荐答案

使用$ http_connection而不是保持活动或升级

using $http_connection instead of keep-alive or upgrade

proxy_set_header Connection $http_connection;

这篇关于.net核心nginx托管套接字不允许http发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆