Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure nginx to support signalr3 under cloudflare?

I am struggling with signalr3 and nginx reverse proxy configuration, my nginx cfg looks like this:

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;
 }
}

What do I miss here?

When I browse my page, I receive OK for

GET /proxy/notifications/negotiate 

and

GET /proxy/notifications?id=uFQtMDg1dXib6LGvUssQhQ

but 404 for POST

POST proxy/notifications?id=uFQtMDg1dXib6LGvUssQhQ

pls halp!

ps. my Hub is very simple...

[AllowAnonymous]
public class NotificationHub : Hub
{

}
like image 235
aph5 Avatar asked Jun 19 '18 21:06

aph5


1 Answers

This is a websocket based app so you need additional nginx config

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; 
}
like image 110
Tarun Lalwani Avatar answered Oct 03 '22 14:10

Tarun Lalwani