问题描述: Nginx做代理时,默认配置不支持WebSocket,而Signalr本质就是WebSocket,所以Signalr服务会被拦截
解决方法: 修改nginx代理设置,需要改代理请求头的设置,/api和/wsApi用于将长连接和短连接分开,如下:
# 启用HTTP长连接支持
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
属性含义:
proxy_http_version 1.1:指定使用http版本,因为只有http1.1才支持长连接;
proxy_set_header Upgrade $http_upgrade:将客户端http请求头Upgrade 透传过来;
roxy_set_header Connection “upgrade”:upgrade意思是告诉服务器使用最高版本协议进行通信;
默认roxy_set_header Connection这里如果不写的话,在htt1.0中Connection 默认是close的,即连接请求完毕后就关闭。