I have a self-hosted blazor web app (plain hello world app), hosted in ubuntu in my home network. Nginx used as reverse proxy; it is setup with a domain name purchased from Namecheap. since it is my home network, I did port forwarding of 80 and 443 from my router to the ubuntu machine. The problem is whenever I open my website using the domain name outside my home network it works fine. If I open the same website using the domain name inside my home network, then it fails with web socket error. After that error, none of the button click works, which means the blazor server interactivity over the signalR is not working in this case.
Setup details below.
=> Linux: 22.04.1-Ubuntu
=> dotnet version: 8.0
=> blazor template: Blazor Web App (.net 8.0).
Uses signalR/websocket as I used "@rendermode InteractiveServer" in Home.razor file.
=> nginx version: nginx/1.24.0
=> my blazor app running on kestrel on port 5000 on the ubuntu machine.
Here is the nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
map $http_connection $connection_upgrade {
"~*Upgrade" $http_connection;
default keep-alive;
}
include /etc/nginx/conf.d/*.conf;
}
here is the conf.d/default.conf
server {
listen 80;
listen [::]:80;
server_name elanall.com *.elanall.com;
location / {
proxy_pass http://127.0.0.1:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
#proxy_set_header Connection $connection_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
#proxy_cache_bypass $http_upgrade;
#proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#proxy_set_header X-Forwarded-Proto $scheme;
}
}
In home network, using another laptop, if I open the ubuntu local IP address it opens fine and connects to websocket as shown below.

In outside network (mobile internet or my friend's home internet), using another laptop, if I open the web address with domain name, then it properly connects to websocket without any issue as shown below. So, I believe there is no issue in hosting it in home network behind a proxy.

In home network, using another laptop, if I open the web address with domain name, then it shows websocket connection error as shown below.

Also tried with ssl certification on 443 and forced redirect to https. still same issue. omitted that part for simplicity as it made no difference in this error. Moreover, tried the same reverse proxy setup with Apache2 on the same machine, but the results are same. So, I believe this is something to do with the hosting+accessing from same network which is somehow messing up with the signalR connection, but not sure why this would happen. Maybe I'm missing some configuration to allow the local machines to access the locally hosted website+websocket using the domain name.
I'm following this MS documentation - https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/linux-nginx?view=aspnetcore-8.0&tabs=linux-ubuntu and also tried searching for solution in online community and tried all configuration whatsoever, but still no success for this specific case.
If anyone have any idea about how to resolve this issue, please share it with me as I'm stuck with this issue for few days now, and don't know how to proceed. thank you!