Problem to use nginx with blazor server 9.0

Hi
i’ve published my blazor server 9.0 to iis on port 82. So it can be accessible via this url :
http://localhost:82

Now, i want to use nginx reverse proxy, to use this address : http://localhost/cis
Which is proxy to http://localhost:82.

Here is nginx.conf script :
server{
listen 80;

	location /cis {
        proxy_pass         http://localhost:82/;
		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;
    }

}

But it doesn’t show up on my desired address (http://localhost/cis).
When check it on my browser developer tools > Network tab, It seems the base address (/cis) found (with 200 Ok), but other resources still looking for this address (for example)(http://localhost/css/site.css)

Which missing /cis base address!
Where is the problem and how to solve problem?

1 Like

Hi @hdv212 - I’ve moved your question over to the Troubleshooting category so it may reach the right folks to help.

1 Like

Did you update the base path in Blazor?

When your app is accessed via /cis, the application is still generating URLs relative to the root path (/) rather than to your desired base path (/cis). This is why resources like CSS files are being requested from /css/site.css instead of /cis/css/site.css.

1 Like

Thanks for reply.
No, How to set base path to blazor?
If i set basePath to my desired, So this is cause some limitation when transfer to another server or rename the url, right?

That’s correct, if you plan to deploy to different environments, I suggest you use an environment variable to set the base path accordingly.

1 Like

Thanks
How to set environment variable to set basePath ?

Sorry, I’m not a Blazor expert. But a quick Google search or ChatGPT would help.

1 Like

Here are some Blazor-specific resources that may help you:

Please do come back when you have NGINX specific questions and we’ll do our best!

2 Likes