Score:0

Can't establish wss connection [React + ASP.NET Core, SignalR + nginx]

bq flag

I have React app that talks to Asp.Net core API. Both of them are deployed on Docker on my VM. Nginx is installed and configured to resolve domain names for app (thesis.uno - for react app, api.thesis.uno - for asp.net core api)

I added chat support to my app using SignalR, but when react tries to establish wss connection through api.thesis.uno it fails enter image description here

When I replace api domain name with VM ip and port, everything seems to function properly, which means that the trouble is in the Nginx configuration.

enter image description here

I tried to google this trouble, but no solution seemed to help me (https://stackoverflow.com/questions/48300288/signalr-in-asp-net-core-behind-nginx, https://stackoverflow.com/questions/12102110/nginx-to-reverse-proxy-websockets-and-enable-ssl-wss)

My nginx config:

client_max_body_size 64M;

upstream backend {
    # enable sticky session based on IP
    ip_hash;

    server localhost:5000;
  }

server {
    root /var/www/thesis.uno/html; # Directly serves anything in the Rails public folder
    index index.html index.htm index.nginx-debian.html;
    server_name thesis.uno www.thesis.uno; # managed by Certbot

    location / {
        proxy_pass http://localhost:5001;
        proxy_set_header Host $host;
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/thesis.uno/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/thesis.uno/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}

server {
    if ($host = www.thesis.uno) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = thesis.uno) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    listen 80 ;
    server_name thesis.uno www.thesis.uno;
    return 404; # managed by Certbot
}

server {
    server_name api.thesis.uno www.api.thesis.uno;

    # all other requests
    location / {
        proxy_pass http://backend;
        proxy_set_header Host $host;
    }

    # web socket chat requests
    location /api/chat {
        proxy_pass http://backend;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $http_connection;
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/api.thesis.uno/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/api.thesis.uno/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}

server {
    if ($host = www.api.thesis.uno) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = api.thesis.uno) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    listen 80;
    server_name api.thesis.uno www.api.thesis.uno;
    return 404; # managed by Certbot
}

UPDATE:

Turned out nginx has a logs file, seems like nginx can't redirect request properly, gives 404 on request

enter image description here

Score:0
xk flag

Is it possible this is related to needing sticky sessions and what this comment mentions as "random 404s" https://github.com/dotnet/AspNetCore.Docs/issues/10827#issuecomment-631088853

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.