Blazor Server APP Deployed on NGINX via Reverse Proxy Returns 404 Not Found for blazor.server.js

Viewed 394

I created a test blazor server app with .NET6 and tried to deploy to a linux server via a reverse proxy on NGINX. The app renders very well but cannot locate the blazor.server.js resource file. I have done the following but didn't get it resolved.

Program.cs

// Configure the HTTP request pipeline.
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
    ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});

if (!app.Environment.IsDevelopment())
{
    //app.UsePathBase(app.Configuration["PathBase"]);
    app.Use((context, next) =>
    {
        context.Request.PathBase = app.Configuration["PathBase"];
        return next();
    });
    app.UseExceptionHandler("/Error");
    // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
    app.UseHsts();
}



app.UseHttpsRedirection();

app.UseStaticFiles();

app.UseRouting();

app.MapBlazorHub();
app.MapFallbackToPage("/_Host");

app.Run();

You would notice app.UsePathBase is commented. When I used it, the app static files didn't display. I had to go with the next line (app.Use...).

I also added ~/ to the script tag in the _Layout.cshtml as seen below;

<script src="~/_framework/blazor.server.js"></script>

NGINX Reverse Proxy

location /blazingdemo {
        proxy_pass         https://localhost:7184/;
        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;
   }

I don't know what else I'm missing. I hope someone can point me to it.

0 Answers
Related