0

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

1 Answer 1

0

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .