简体   繁体   中英

Blazor server side behind reverse proxy 404

I have a blazor server-side app hosted on IIS behind a reverse proxy (using ARR).

I have tried everything I can think of, but I keep getting 404 on

_framework/blazor.server.js

My base href is is set to "/subsite/":

<base href="/subsite/" />

and all my src values are relative like this:

<script src="_framework/blazor.server.js"></script>
<script src="_content/BlazorInputFile/inputfile.js"></script>
<script src="animations.js"></script>

Every other script ref loads fine, EVEN the _content data, but not the blazor.server.js.

I tried the old PathBase trick for MVC apps as well with no success:

if (!env.IsDevelopment()) {
    app.Use((context, next) => {
        context.Request.PathBase = new PathString("/subsite");
        return next();
    });
}

Can anyone tell me how to make Blazor realize where to put the blazor.server.js in a reverse proxy scenario?

Did you try the UsePathBase?

app.UsePathBase("/subsite");

Here is my test result

测试结果

Please check this article for more https://www.billbogaiv.com/posts/net-core-hosted-on-subdirectories-in-nginx

From docs .

Rewrite URLs for correct routing

Routing requests for page components in a Blazor WebAssembly app isn't as straightforward as routing requests in a Blazor Server, hosted app. Consider a Blazor WebAssembly app with two components:

  • Main.razor – Loads at the root of the app and contains a link to the About component ( href="About" ).
  • About.razorAbout component.

When the app's default document is requested using the browser's address bar (for example, https://www.contoso.com/ ):

  • The browser makes a request.
  • The default page is returned, which is usually index.html .
  • index.html bootstraps the app.
  • Blazor's router loads, and the Razor Main component is rendered.

In the Main page, selecting the link to the About component works on the client because the Blazor router stops the browser from making a request on the Internet to www.contoso.com for About and serves the rendered About component itself. All of the requests for internal endpoints within the Blazor WebAssembly app work the same way: Requests don't trigger browser-based requests to server-hosted resources on the Internet. The router handles the requests internally.

If a request is made using the browser's address bar for www.contoso.com/About , the request fails. No such resource exists on the app's Internet host, so a 404 - Not Found response is returned.

Because browsers make requests to Internet-based hosts for client-side pages, web servers and hosting services must rewrite all requests for resources not physically on the server to the index.html page. When index.html is returned, the app's Blazor router takes over and responds with the correct resource.

When deploying to an IIS server, you can use the URL Rewrite Module with the app's published web.config file. For more information, see the IIS section.


Maybe you could try to enable the forward proxy in IIS manager->server node->application request routing cache->proxy->enable.

If you only have one website, you could just add the website to ARR server farm and then it will create the routing rule automatically. It will be convenient to monitor the back-end server with health check.

Is this ARR warning causing my 404?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM