.NET Blazor hosting on Nginx - API issue

37 Views Asked by At

I would appreciate some help if possible......

We have a .NET Blazor web application with API project. We are attempting to host this on Nginx running on Kubuntu.

We have followed the guidance available on the Microsoft web site, but are having issues with the web front-end communicating with the API back end.

The set up we have is a published front-end project running through an Nginx .conf file (below 1) with proxy pass to a kestrel service file (below 2). The API project is running on a second kestrel service file (below 3).

Ngnix hosts the website on the expected port and it loads fine. The API project is hosted on the expected port and the methods can be called directly through the browser/curl.

However, the hosted web site cannot connect to the API backend - as soon as we interact with the website and an API call is required, a websocket error is thrown in the browser console. I'm not sure if it's a port configuration issue, we are missing some config with the kestrel service files, or need to edit some code in the solution in VS.

Any help would be great!

  1. Nginx Config file:
server {
    listen 80;
    server_name   "";
    location / {
        proxy_pass         http://127.0.0.1:5099;
        proxy_http_version 1.1;
        proxy_set_header   Upgrade $http_upgrade;
        proxy_set_header   Connection keep-alive;
        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;
        proxy_set_header   Connection "Upgrade";
    }
}
  1. kestrel service file - front-end
[Unit]
Description=TCWEB

[Service]
WorkingDirectory=/home/tcweb/Desktop/PublishedApplication/TC/LIVE/web
ExecStart=/usr/bin/dotnet /home/tcweb/Desktop/PublishedApplication/TC/LIVE/web/TC.Server.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=tcweb
User=tcweb
Environment=ASPNETCORE_ENVIRONMENT=Development
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
Environment=ASPNETCORE_URLS=http://localhost:5099

[Install]
WantedBy=multi-user.target
  1. Kestel service file - API backend
[Unit]
Description=TCAPI

[Service]
WorkingDirectory=/home/tcweb/Desktop/PublishedApplication/TC/LIVE/api
ExecStart=/usr/bin/dotnet /home/tcweb/Desktop/PublishedApplication/TC/LIVE/api/TC.Api.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=tcapi
User=tcweb
Environment=ASPNETCORE_ENVIRONMENT=Development
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
Environment=ASPNETCORE_URLS=http://localhost:7112

[Install]
WantedBy=multi-user.target
0

There are 0 best solutions below