如何配置Nginx在cloudflare下支持signalr3?

时间:2018-06-19 21:54:13

标签: asp.net nginx signalr nginx-reverse-proxy

我正在努力处理signalr3和nginx反向代理配置,我的nginx cfg看起来像这样:

server {
listen       80;
server_name  my.customdomain.com;

location / {
  root /pages/my.customdomain.com;
  index index.html index.htm;
  try_files $uri $uri/ /index.html =404;
}

## send request back to kestrel ##
location /proxy/ {
 proxy_pass  http://xxxxxxxxxx.westeurope.cloudapp.azure.com/;

 proxy_set_header        Host            $host;
 proxy_set_header        X-Real-IP       $remote_addr;
 proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
 }
}

我在这里想念什么?

浏览页面时,我收到

的确定
GET /proxy/notifications/negotiate 

GET /proxy/notifications?id=uFQtMDg1dXib6LGvUssQhQ

但POST时为404

POST proxy/notifications?id=uFQtMDg1dXib6LGvUssQhQ

请暂停!

ps。我的集线器非常简单...

[AllowAnonymous]
public class NotificationHub : Hub
{

}

1 个答案:

答案 0 :(得分:3)

这是一个基于websocket的应用程序,因此您需要其他nginx配置

location / { 
    proxy_set_header X-Real-IP $remote_addr; 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_set_header X-NginX-Proxy true; 
    #proxy_set_header X-Forwarded-Proto https; 
    proxy_pass 127.0.0.1:8080; 
    proxy_set_header Upgrade $http_upgrade; 
    proxy_set_header Connection "upgrade";
    proxy_ssl_session_reuse off; 
    proxy_set_header Host $http_host; 
    proxy_cache_bypass $http_upgrade; 
    proxy_redirect off; 
}