You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
title: Host and deploy ASP.NET Core Blazor WebAssembly with Nginx
3
+
ai-usage: ai-assisted
3
4
author: guardrex
4
5
description: Learn how to host and deploy Blazor WebAssembly using Nginx.
5
6
monikerRange: '>= aspnetcore-3.1'
6
7
ms.author: wpickett
7
8
ms.custom: mvc, linux-related-content
8
-
ms.date: 11/11/2025
9
+
ms.date: 01/21/2026
9
10
uid: blazor/host-and-deploy/webassembly/nginx
10
11
---
11
12
# Host and deploy ASP.NET Core Blazor WebAssembly with Nginx
12
13
14
+
By [Andrii Annenko](https://github.com/aannenko)
15
+
13
16
[!INCLUDE[](~/includes/not-latest-version.md)]
14
17
15
-
This article explains how to host and deploy Blazor WebAssembly using [Nginx](https://nginx.org/).
18
+
This article explains how to host and deploy Blazor WebAssembly that targets .NET 8, 9 or 10 using [Nginx](https://nginx.org/).
16
19
17
-
The following `nginx.conf` file is simplified to show how to configure Nginx to send the `index.html` file whenever it can't find a corresponding file on disk.
20
+
This article covers deploying the app either directly on a host or in a Docker container that includes Nginx and the published app's files. The Docker hosting section covers publishing the app, copying the published output to Nginx's web root in the container image, configuring Nginx for client-side routing, and applying common production settings.
18
21
19
-
```
22
+
## Minimal Nginx configuration
23
+
24
+
The following `nginx.conf` file is a minimal Nginx configuration example showing how to configure Nginx to send the `index.html` file whenever it can't find a corresponding file on disk. It also directs Nginx to serve correct MIME types by defining a `types` block (alternatively, include a [`mime.types`](https://github.com/nginx/nginx/blob/7fa941a55e211ebd57f512fbfb24d59dbb97940d/conf/mime.types) file).
25
+
26
+
```nginx
20
27
events { }
21
28
http {
29
+
types {
30
+
text/html html;
31
+
text/css css;
32
+
application/javascript js mjs;
33
+
application/json json;
34
+
application/manifest+json webmanifest;
35
+
36
+
application/wasm wasm;
37
+
38
+
application/octet-stream dll pdb webcil;
39
+
}
40
+
22
41
server {
23
42
listen 80;
24
43
25
44
location / {
26
-
root /usr/share/nginx/html;
45
+
root /usr/share/nginx/html;
27
46
try_files $uri $uri/ /index.html =404;
28
47
}
29
48
}
30
49
}
31
50
```
32
51
33
-
When setting the [NGINX burst rate limit](https://www.nginx.com/blog/rate-limiting-nginx/#bursts) with [`limit_req`](https://nginx.org/docs/http/ngx_http_limit_req_module.html#limit_req) and [`limit_req_zone`](https://nginx.org/docs/http/ngx_http_limit_req_module.html), Blazor WebAssembly apps may require a large `burst`/`rate` parameter values to accommodate the relatively large number of requests made by an app. Initially, set the value to at least 60:
52
+
## Complete Nginx configuration
34
53
35
-
```
54
+
The following `nginx.conf` example builds on the minimal configuration. It includes optional settings for caching, compression, rate limiting, and security headers. Review the comments and remove or adjust settings based on your app's requirements.
55
+
56
+
```nginx
57
+
events { }
36
58
http {
59
+
# Security hardening: Don't reveal the Nginx version in responses.
60
+
server_tokens off;
61
+
62
+
# Optional: Rate limiting to prevent a single client from sending too
63
+
# many requests.
64
+
# Blazor WebAssembly apps can generate many requests during startup.
Increase the value if browser developer tools or a network traffic tool indicates that requests are receiving a *503 - Service Unavailable* status code.
143
+
If browser developer tools or a network traffic tool indicates that requests are receiving a *503 - Service Unavailable* status code, increase the `rate` and `burst` values.
51
144
52
145
For more information on production Nginx web server configuration, see [Creating NGINX Plus and NGINX Configuration Files](https://docs.nginx.com/nginx/admin-guide/basic-functionality/managing-configuration-files/).
53
146
147
+
## Docker deployment
148
+
149
+
The following Dockerfile publishes a Blazor WebAssembly app and serves the app's static web assets from an Nginx image.
150
+
151
+
The example assumes that:
152
+
153
+
* The app's project file is named `BlazorSample.csproj` and located at the Docker build context root.
154
+
* An `nginx.conf` file is available at the Docker build context root.
155
+
156
+
For example, `Dockerfile`, `nginx.conf` and `BlazorSample.csproj` are all located in the same directory where the rest of Blazor code is also located. In this case, `docker build` is launched in this working directory.
157
+
158
+
```dockerfile
159
+
# Build stage
160
+
# IMPORTANT: change the dotnet/sdk version to the one that your Blazor app targets
161
+
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:10.0-noble AS build
162
+
WORKDIR /source
163
+
164
+
RUN apt update \
165
+
&& apt install -y python3 \
166
+
&& dotnet workload install wasm-tools
167
+
168
+
COPY . .
169
+
RUN dotnet publish BlazorSample.csproj --output /app
0 commit comments