diff --git a/aspnetcore/fundamentals/servers/kestrel/endpoints.md b/aspnetcore/fundamentals/servers/kestrel/endpoints.md index b17db3dc1a58..8fad7a49ca8a 100644 --- a/aspnetcore/fundamentals/servers/kestrel/endpoints.md +++ b/aspnetcore/fundamentals/servers/kestrel/endpoints.md @@ -37,7 +37,7 @@ Some browsers require granting explicit permission to trust the local developmen Project templates configure apps to run on HTTPS by default and include [HTTPS redirection and HSTS support](xref:security/enforcing-ssl). -Call or methods on to configure URL prefixes and ports for Kestrel. +Call or methods on to configure URL prefixes and ports for Kestrel. `UseUrls`, the `--urls` command-line argument, `urls` host configuration key, and the `ASPNETCORE_URLS` environment variable also work but have the limitations noted later in this section (a default certificate must be available for HTTPS endpoint configuration). @@ -58,7 +58,7 @@ webBuilder.ConfigureKestrel(serverOptions => ``` > [!NOTE] -> Endpoints created by calling **before** calling won't have the defaults applied. +> Endpoints created by calling **before** calling won't have the defaults applied. ## ConfigureHttpsDefaults(Action\) @@ -76,7 +76,7 @@ webBuilder.ConfigureKestrel(serverOptions => ``` > [!NOTE] -> Endpoints created by calling **before** calling won't have the defaults applied. +> Endpoints created by calling **before** calling won't have the defaults applied. ## Configure(IConfiguration) @@ -131,8 +131,8 @@ Kestrel listens on `http://localhost:5000` and `https://localhost:5001` (if a de In the following *appsettings.json* example: -* Set **AllowInvalid** to `true` to permit the use of invalid certificates (for example, self-signed certificates). -* Any HTTPS endpoint that doesn't specify a certificate (**HttpsDefaultCert** in the example that follows) falls back to the cert defined under **Certificates** > **Default** or the development certificate. +* Set `AllowInvalid` to `true` to permit the use of invalid certificates (for example, self-signed certificates). +* Any HTTPS endpoint that doesn't specify a certificate (`HttpsDefaultCert` in the example that follows) falls back to the cert defined under `Certificates` > `Default` or the development certificate. ```json { @@ -178,7 +178,7 @@ In the following *appsettings.json* example: } ``` -An alternative to using **Path** and **Password** for any certificate node is to specify the certificate using certificate store fields. For example, the **Certificates** > **Default** certificate can be specified as: +An alternative to using `Path` and `Password` for any certificate node is to specify the certificate using certificate store fields. For example, the `Certificates` > `Default` certificate can be specified as: ```json "Default": { @@ -195,7 +195,7 @@ Schema notes: * The `Url` parameter is required for each endpoint. The format for this parameter is the same as the top-level `Urls` configuration parameter except that it's limited to a single value. * These endpoints replace those defined in the top-level `Urls` configuration rather than adding to them. Endpoints defined in code via `Listen` are cumulative with the endpoints defined in the configuration section. * The `Certificate` section is optional. If the `Certificate` section isn't specified, the defaults defined in earlier scenarios are used. If no defaults are available, the server throws an exception and fails to start. -* The `Certificate` section supports both **Path**–**Password** and **Subject**–**Store** certificates. +* The `Certificate` section supports both `Path`–`Password` and `Subject`–`Store` certificates. * Any number of endpoints may be defined in this way so long as they don't cause port conflicts. * `options.Configure(context.Configuration.GetSection("{SECTION}"))` returns a `KestrelConfigurationLoader` with an `.Endpoint(string name, listenOptions => { })` method that can be used to supplement a configured endpoint's settings: @@ -210,7 +210,7 @@ webBuilder.UseKestrel((context, serverOptions) => }); ``` -`KestrelServerOptions.ConfigurationLoader` can be directly accessed to continue iterating on the existing loader, such as the one provided by . +`KestrelServerOptions.ConfigurationLoader` can be directly accessed to continue iterating on the existing loader, such as the one provided by . * The configuration section for each endpoint is available on the options in the `Endpoint` method so that custom settings may be read. * Multiple configurations may be loaded by calling `options.Configure(context.Configuration.GetSection("{SECTION}"))` again with another section. Only the last configuration is used, unless `Load` is explicitly called on prior instances. The metapackage doesn't call `Load` so that its default configuration section may be replaced. @@ -235,7 +235,7 @@ webBuilder.ConfigureKestrel(serverOptions => }); ``` -## Configure endpoints using SNI +## Configure endpoints using Server Name Indication [Server Name Indication (SNI)](https://tools.ietf.org/html/rfc6066#section-3) can be used to host multiple domains on the same IP address and port. For SNI to function, the client sends the host name for the secure session to the server during the TLS handshake so that the server can provide the correct certificate. The client uses the furnished certificate for encrypted communication with the server during the secure session that follows the TLS handshake. @@ -288,7 +288,7 @@ webBuilder.ConfigureKestrel(serverOptions => ## Connection logging -Call to emit Debug level logs for byte-level communication on a connection. Connection logging is helpful for troubleshooting problems in low-level communication, such as during TLS encryption and behind proxies. If `UseConnectionLogging` is placed before `UseHttps`, encrypted traffic is logged. If `UseConnectionLogging` is placed after `UseHttps`, decrypted traffic is logged. This is built-in [Connection Middleware](#connection-middleware). +Call to emit Debug level logs for byte-level communication on a connection. Connection logging is helpful for troubleshooting problems in low-level communication, such as during TLS encryption and behind proxies. If `UseConnectionLogging` is placed before `UseHttps`, encrypted traffic is logged. If `UseConnectionLogging` is placed after `UseHttps`, decrypted traffic is logged. This is built-in [Connection Middleware](#connection-middleware). ```csharp webBuilder.ConfigureKestrel(serverOptions => @@ -302,7 +302,7 @@ webBuilder.ConfigureKestrel(serverOptions => ## Bind to a TCP socket -The method binds to a TCP socket, and an options lambda permits X.509 certificate configuration: +The method binds to a TCP socket, and an options lambda permits X.509 certificate configuration: [!code-csharp[](samples/5.x/KestrelSample/Program.cs?name=snippet_TCPSocket&highlight=12-18)] @@ -312,16 +312,16 @@ The example configures HTTPS for an endpoint with for improved performance with Nginx, as shown in this example: +Listen on a Unix socket with for improved performance with Nginx, as shown in this example: [!code-csharp[](samples/5.x/KestrelSample/Program.cs?name=snippet_UnixSocket)] -* In the Nginx configuration file, set the `server` > `location` > `proxy_pass` entry to `http://unix:/tmp/{KESTREL SOCKET}:/;`. `{KESTREL SOCKET}` is the name of the socket provided to (for example, `kestrel-test.sock` in the preceding example). +* In the Nginx configuration file, set the `server` > `location` > `proxy_pass` entry to `http://unix:/tmp/{KESTREL SOCKET}:/;`. `{KESTREL SOCKET}` is the name of the socket provided to (for example, `kestrel-test.sock` in the preceding example). * Ensure that the socket is writeable by Nginx (for example, `chmod go+w /tmp/kestrel-test.sock`). ## Port 0 -When the port number `0` is specified, Kestrel dynamically binds to an available port. The following example shows how to determine which port Kestrel actually bound at runtime: +When the port number `0` is specified, Kestrel dynamically binds to an available port. The following example shows how to determine which port Kestrel bound at runtime: [!code-csharp[](samples/5.x/KestrelSample/Startup.cs?name=snippet_Configure&highlight=3-4,15-21)] @@ -335,19 +335,19 @@ Listening on the following addresses: http://127.0.0.1:48508 Configure endpoints with the following approaches: -* +* * `--urls` command-line argument * `urls` host configuration key * `ASPNETCORE_URLS` environment variable These methods are useful for making code work with servers other than Kestrel. However, be aware of the following limitations: -* HTTPS can't be used with these approaches unless a default certificate is provided in the HTTPS endpoint configuration (for example, using `KestrelServerOptions` configuration or a configuration file as shown earlier in this topic). +* HTTPS can't be used with these approaches unless a default certificate is provided in the HTTPS endpoint configuration (for example, using `KestrelServerOptions` configuration or a configuration file as shown earlier in this article). * When both the `Listen` and `UseUrls` approaches are used simultaneously, the `Listen` endpoints override the `UseUrls` endpoints. ## IIS endpoint configuration -When using IIS, the URL bindings for IIS override bindings are set by either `Listen` or `UseUrls`. For more information, see the [ASP.NET Core Module](xref:host-and-deploy/aspnet-core-module) topic. +When using IIS, the URL bindings for IIS override bindings are set by either `Listen` or `UseUrls`. For more information, see [ASP.NET Core Module](xref:host-and-deploy/aspnet-core-module). ## ListenOptions.Protocols @@ -414,7 +414,7 @@ webBuilder.ConfigureKestrel(serverOptions => ## Connection Middleware -Custom connection middleware can filter TLS handshakes on a per-connection basis for specific ciphers if required. +Custom connection middleware can filter TLS handshakes on a per-connection basis for specific ciphers if necessary. The following example throws for any cipher algorithm that the app doesn't support. Alternatively, define and compare [ITlsHandshakeFeature.CipherAlgorithm](xref:Microsoft.AspNetCore.Connections.Features.ITlsHandshakeFeature.CipherAlgorithm) to a list of acceptable cipher suites. @@ -555,7 +555,7 @@ Only HTTP URL prefixes are valid. Kestrel doesn't support HTTPS when configuring http://*:80/ ``` - Host names, `*`, and `+`, aren't special. Anything not recognized as a valid IP address or `localhost` binds to all IPv4 and IPv6 IPs. To bind different host names to different ASP.NET Core apps on the same port, use [HTTP.sys](xref:fundamentals/servers/httpsys) or a reverse proxy server, such as IIS, Nginx, or Apache. + Host names, `*`, and `+`, aren't special. Anything not recognized as a valid IP address or `localhost` binds to all IPv4 and IPv6 IPs. To bind different host names to different ASP.NET Core apps on the same port, use [HTTP.sys](xref:fundamentals/servers/httpsys) or a reverse proxy server. Reverse proxy server examples include IIS, Nginx, or Apache. > [!WARNING] > Hosting in a reverse proxy configuration requires [host filtering](xref:fundamentals/servers/kestrel/host-filtering). diff --git a/aspnetcore/fundamentals/servers/kestrel/host-filtering.md b/aspnetcore/fundamentals/servers/kestrel/host-filtering.md index 57f5c6969cf3..fcddeb95cdd2 100644 --- a/aspnetcore/fundamentals/servers/kestrel/host-filtering.md +++ b/aspnetcore/fundamentals/servers/kestrel/host-filtering.md @@ -14,7 +14,7 @@ uid: fundamentals/servers/kestrel/host-filtering While Kestrel supports configuration based on prefixes such as `http://example.com:5000`, Kestrel largely ignores the host name. Host `localhost` is a special case used for binding to loopback addresses. Any host other than an explicit IP address binds to all public IP addresses. `Host` headers aren't validated. -As a workaround, use Host Filtering Middleware. Host Filtering Middleware is provided by the [Microsoft.AspNetCore.HostFiltering](https://www.nuget.org/packages/Microsoft.AspNetCore.HostFiltering) package, which is implicitly provided for ASP.NET Core apps. The middleware is added by , which calls : +As a workaround, use Host Filtering Middleware. Host Filtering Middleware is provided by the [Microsoft.AspNetCore.HostFiltering](https://www.nuget.org/packages/Microsoft.AspNetCore.HostFiltering) package, which is implicitly provided for ASP.NET Core apps. The middleware is added by , which calls : [!code-csharp[](samples-snapshot/2.x/KestrelSample/Program.cs?name=snippet_Program&highlight=9)] diff --git a/aspnetcore/fundamentals/servers/kestrel/http2.md b/aspnetcore/fundamentals/servers/kestrel/http2.md index 7b80bfef0c29..fc5ca25f122f 100644 --- a/aspnetcore/fundamentals/servers/kestrel/http2.md +++ b/aspnetcore/fundamentals/servers/kestrel/http2.md @@ -24,7 +24,7 @@ uid: fundamentals/servers/kestrel/http2 †HTTP/2 will be supported on macOS in a future release. ‡Kestrel has limited support for HTTP/2 on Windows Server 2012 R2 and Windows 8.1. Support is limited because the list of supported TLS cipher suites available on these operating systems is limited. A certificate generated using an Elliptic Curve Digital Signature Algorithm (ECDSA) may be required to secure TLS connections. -If an HTTP/2 connection is established, [HttpRequest.Protocol](xref:Microsoft.AspNetCore.Http.HttpRequest.Protocol*) reports `HTTP/2`. +If an HTTP/2 connection is established, [HttpRequest.Protocol](xref:Microsoft.AspNetCore.Http.HttpRequest.Protocol%2A) reports `HTTP/2`. Starting with .NET Core 3.0, HTTP/2 is enabled by default. For more information on configuration, see the [Kestrel HTTP/2 limits](xref:fundamentals/servers/kestrel/options#http2-limits) and [ListenOptions.Protocols](xref:fundamentals/servers/kestrel/endpoints#listenoptionsprotocols) sections. diff --git a/aspnetcore/fundamentals/servers/kestrel/options.md b/aspnetcore/fundamentals/servers/kestrel/options.md index d936179e8377..6a8c90a91657 100644 --- a/aspnetcore/fundamentals/servers/kestrel/options.md +++ b/aspnetcore/fundamentals/servers/kestrel/options.md @@ -156,16 +156,16 @@ Override the setting on a specific request in middleware: An exception is thrown if the app configures the limit on a request after the app has started to read the request. There's an `IsReadOnly` property that indicates if the `MaxRequestBodySize` property is in read-only state, meaning it's too late to configure the limit. -When an app is run [out-of-process](xref:host-and-deploy/iis/index#out-of-process-hosting-model) behind the [ASP.NET Core Module](xref:host-and-deploy/aspnet-core-module), Kestrel's request body size limit is disabled because IIS already sets the limit. +When an app runs [out-of-process](xref:host-and-deploy/iis/index#out-of-process-hosting-model) behind the [ASP.NET Core Module](xref:host-and-deploy/aspnet-core-module), Kestrel's request body size limit is disabled. IIS already sets the limit. ### Minimum request body data rate -Kestrel checks every second if data is arriving at the specified rate in bytes/second. If the rate drops below the minimum, the connection is timed out. The grace period is the amount of time that Kestrel gives the client to increase its send rate up to the minimum; the rate isn't checked during that time. The grace period helps avoid dropping connections that are initially sending data at a slow rate due to TCP slow-start. +Kestrel checks every second if data is arriving at the specified rate in bytes/second. If the rate drops below the minimum, the connection is timed out. The grace period is the amount of time Kestrel allows the client to increase its send rate up to the minimum. The rate isn't checked during that time. The grace period helps avoid dropping connections that are initially sending data at a slow rate because of TCP slow-start. -The default minimum rate is 240 bytes/second with a 5 second grace period. +The default minimum rate is 240 bytes/second with a 5-second grace period. A minimum rate also applies to the response. The code to set the request limit and the response limit is the same except for having `RequestBody` or `Response` in the property and interface names. @@ -177,7 +177,7 @@ Override the minimum rate limits per request in middleware: [!code-csharp[](samples/3.x/KestrelSample/Startup.cs?name=snippet_Limits&highlight=6-21)] -The referenced in the prior sample is not present in `HttpContext.Features` for HTTP/2 requests because modifying rate limits on a per-request basis is generally not supported for HTTP/2 due to the protocol's support for request multiplexing. However, the is still present `HttpContext.Features` for HTTP/2 requests, because the read rate limit can still be *disabled entirely* on a per-request basis by setting `IHttpMinRequestBodyDataRateFeature.MinDataRate` to `null` even for an HTTP/2 request. Attempting to read `IHttpMinRequestBodyDataRateFeature.MinDataRate` or attempting to set it to a value other than `null` will result in a `NotSupportedException` being thrown given an HTTP/2 request. +The referenced in the prior sample isn't present in `HttpContext.Features` for HTTP/2 requests. Modifying rate limits on a per-request basis is generally not supported for HTTP/2 because of the protocol's support for request multiplexing. However, the is still present `HttpContext.Features` for HTTP/2 requests, because the read rate limit can still be *disabled entirely* on a per-request basis by setting `IHttpMinRequestBodyDataRateFeature.MinDataRate` to `null` even for an HTTP/2 request. Attempting to read `IHttpMinRequestBodyDataRateFeature.MinDataRate` or attempting to set it to a value other than `null` will result in a `NotSupportedException` being thrown given an HTTP/2 request. Server-wide rate limits configured via `KestrelServerOptions.Limits` still apply to both HTTP/1.x and HTTP/2 connections. @@ -278,7 +278,7 @@ Kestrel can be configured to send HTTP/2 pings to connected clients. HTTP/2 ping There are two configuration options related to HTTP/2 keep alive pings: -* `Http2.KeepAlivePingInterval` is a `TimeSpan` that configures the ping internal. The server sends a keep alive ping to the client if it doesn't receive any frames for this period of time. Keep alive pings are disabled when this option is set to `TimeSpan.MaxValue`. The default value is `TimeSpan.MaxValue`. +* `Http2.KeepAlivePingInterval` is a `TimeSpan` that configures the ping interval. The server sends a keep alive ping to the client if it doesn't receive any frames for this period of time. Keep alive pings are disabled when this option is set to `TimeSpan.MaxValue`. The default value is `TimeSpan.MaxValue`. * `Http2.KeepAlivePingTimeout` is a `TimeSpan` that configures the ping timeout. If the server doesn't receive any frames, such as a response ping, during this timeout then the connection is closed. Keep alive timeout is disabled when this option is set to `TimeSpan.MaxValue`. The default value is 20 seconds. ```csharp diff --git a/aspnetcore/fundamentals/servers/kestrel/request-draining.md b/aspnetcore/fundamentals/servers/kestrel/request-draining.md index 276124f2e076..3bebe227d992 100644 --- a/aspnetcore/fundamentals/servers/kestrel/request-draining.md +++ b/aspnetcore/fundamentals/servers/kestrel/request-draining.md @@ -12,30 +12,30 @@ uid: fundamentals/servers/kestrel/request-draining # Request draining with ASP.NET Core Kestrel web server -Opening HTTP connections is time consuming. For HTTPS, it's also resource intensive. Therefore, Kestrel tries to reuse connections per the HTTP/1.1 protocol. A request body must be fully consumed to allow the connection to be reused. The app doesn't always consume the request body, such as a `POST` requests where the server returns a redirect or 404 response. In the `POST`-redirect case: +Opening HTTP connections is time consuming. For HTTPS, it's also resource intensive. Therefore, Kestrel tries to reuse connections per the HTTP/1.1 protocol. A request body must be fully consumed to allow the connection to be reused. The app doesn't always consume the request body, such as HTTP POST requests where the server returns a redirect or 404 response. In the HTTP POST redirect case: -* The client may already have sent part of the `POST` data. +* The client may already have sent part of the POST data. * The server writes the 301 response. -* The connection can't be used for a new request until the `POST` data from the previous request body has been fully read. +* The connection can't be used for a new request until the POST data from the previous request body has been fully read. * Kestrel tries to drain the request body. Draining the request body means reading and discarding the data without processing it. -The draining process makes a tradoff between allowing the connection to be reused and the time it takes to drain any remaining data: +The draining process makes a tradeoff between allowing the connection to be reused and the time it takes to drain any remaining data: * Draining has a timeout of five seconds, which isn't configurable. * If all of the data specified by the `Content-Length` or `Transfer-Encoding` header hasn't been read before the timeout, the connection is closed. -Sometimes you may want to terminate the request immediately, before or after writing the response. For example, clients may have restrictive data caps, so limiting uploaded data might be a priority. In such cases to terminate a request, call [HttpContext.Abort](xref:Microsoft.AspNetCore.Http.HttpContext.Abort%2A) from a controller, Razor Page, or middleware. +Sometimes you may want to terminate the request immediately, before or after writing the response. For example, clients may have restrictive data caps. Limiting uploaded data might be a priority. In such cases to terminate a request, call [HttpContext.Abort](xref:Microsoft.AspNetCore.Http.HttpContext.Abort%2A) from a controller, Razor Page, or middleware. There are caveats to calling `Abort`: * Creating new connections can be slow and expensive. * There's no guarantee that the client has read the response before the connection closes. * Calling `Abort` should be rare and reserved for severe error cases, not common errors. - * Only call `Abort` when a specific problem needs to be solved. For example, call `Abort` if malicious clients are trying to `POST` data or when there's a bug in client code that causes large or numerous requests. + * Only call `Abort` when a specific problem needs to be solved. For example, call `Abort` if malicious clients are trying to POST data or when there's a bug in client code that causes large or several requests. * Don't call `Abort` for common error situations, such as HTTP 404 (Not Found). Calling [HttpResponse.CompleteAsync](xref:Microsoft.AspNetCore.Http.HttpResponse.CompleteAsync%2A) before calling `Abort` ensures that the server has completed writing the response. However, client behavior isn't predictable and they may not read the response before the connection is aborted. -This process is different for HTTP/2 because the protocol supports aborting individual request streams without closing the connection. The five second drain timeout doesn't apply. If there's any unread request body data after completing a response, then the server sends an HTTP/2 RST frame. Additional request body data frames are ignored. +This process is different for HTTP/2 because the protocol supports aborting individual request streams without closing the connection. The five-second drain timeout doesn't apply. If there's any unread request body data after completing a response, then the server sends an HTTP/2 RST frame. Additional request body data frames are ignored. -If possible, it's better for clients to utilize the [Expect: 100-continue](https://developer.mozilla.org/docs/Web/HTTP/Status/100) request header and wait for the server to respond before starting to send the request body. That gives the client an opportunity to examine the response and abort before sending unneeded data. +If possible, it's better for clients to use the [Expect: 100-continue](https://developer.mozilla.org/docs/Web/HTTP/Status/100) request header and wait for the server to respond before starting to send the request body. That gives the client an opportunity to examine the response and abort before sending unneeded data. diff --git a/aspnetcore/fundamentals/servers/kestrel/when-to-use-a-reverse-proxy.md b/aspnetcore/fundamentals/servers/kestrel/when-to-use-a-reverse-proxy.md index a4fe39330f08..a80fca497ff6 100644 --- a/aspnetcore/fundamentals/servers/kestrel/when-to-use-a-reverse-proxy.md +++ b/aspnetcore/fundamentals/servers/kestrel/when-to-use-a-reverse-proxy.md @@ -24,7 +24,7 @@ Kestrel used in a reverse proxy configuration: Either configuration, with or without a reverse proxy server, is a supported hosting configuration. -Kestrel used as an edge server without a reverse proxy server doesn't support sharing the same IP and port among multiple processes. When Kestrel is configured to listen on a port, Kestrel handles all of the traffic for that port regardless of requests' `Host` headers. A reverse proxy that can share ports has the ability to forward requests to Kestrel on a unique IP and port. +When Kestrel is used as an edge server without a reverse proxy server, sharing of the same IP address and port among multiple processes is unsupported. When Kestrel is configured to listen on a port, Kestrel handles all traffic for that port regardless of requests' `Host` headers. A reverse proxy that can share ports can forward requests to Kestrel on a unique IP and port. Even if a reverse proxy server isn't required, using a reverse proxy server might be a good choice. diff --git a/aspnetcore/grpc/aspnetcore.md b/aspnetcore/grpc/aspnetcore.md index 48ef4f71a983..2440c6d951d4 100644 --- a/aspnetcore/grpc/aspnetcore.md +++ b/aspnetcore/grpc/aspnetcore.md @@ -4,7 +4,7 @@ author: juntaoluo description: Learn the basic concepts when writing gRPC services with ASP.NET Core. monikerRange: '>= aspnetcore-3.0' ms.author: johluo -ms.date: 09/03/2019 +ms.date: 01/14/2021 no-loc: [appsettings.json, "ASP.NET Core Identity", cookie, Cookie, Blazor, "Blazor Server", "Blazor WebAssembly", "Identity", "Let's Encrypt", Razor, SignalR] uid: grpc/aspnetcore --- @@ -58,9 +58,10 @@ In *Startup.cs*: [!code-csharp[](~/tutorials/grpc/grpc-start/sample/GrpcGreeter/Startup.cs?name=snippet&highlight=7,24)] [!INCLUDE[about the series](~/includes/code-comments-loc.md)] -ASP.NET Core middlewares and features share the routing pipeline, therefore an app can be configured to serve additional request handlers. The additional request handlers, such as MVC controllers, work in parallel with the configured gRPC services. +ASP.NET Core middleware and features share the routing pipeline, therefore an app can be configured to serve additional request handlers. The additional request handlers, such as MVC controllers, work in parallel with the configured gRPC services. ::: moniker range=">= aspnetcore-5.0" + ### Configure Kestrel Kestrel gRPC endpoints: @@ -70,7 +71,7 @@ Kestrel gRPC endpoints: #### HTTP/2 -gRPC requires HTTP/2. gRPC for ASP.NET Core validates [HttpRequest.Protocol](xref:Microsoft.AspNetCore.Http.HttpRequest.Protocol*) is `HTTP/2`. +gRPC requires HTTP/2. gRPC for ASP.NET Core validates [HttpRequest.Protocol](xref:Microsoft.AspNetCore.Http.HttpRequest.Protocol%2A) is `HTTP/2`. Kestrel [supports HTTP/2](xref:fundamentals/servers/kestrel/http2) on most modern operating systems. Kestrel endpoints are configured to support HTTP/1.1 and HTTP/2 connections by default. @@ -90,7 +91,7 @@ Alternatively, Kestrel endpoints can be configured in *Program.cs*: TLS is used for more than securing communication. The TLS [Application-Layer Protocol Negotiation (ALPN)](https://tools.ietf.org/html/rfc7301#section-3) handshake is used to negotiate the connection protocol between the client and the server when an endpoint supports multiple protocols. This negotiation determines whether the connection uses HTTP/1.1 or HTTP/2. -If an HTTP/2 endpoint is configured without TLS, the endpoint's [ListenOptions.Protocols](xref:fundamentals/servers/kestrel/endpoints#listenoptionsprotocols) must be set to `HttpProtocols.Http2`. An endpoint with multiple protocols (for example, `HttpProtocols.Http1AndHttp2`) can't be used without TLS because there is no negotiation. All connections to the unsecured endpoint default to HTTP/1.1, and gRPC calls fail. +If an HTTP/2 endpoint is configured without TLS, the endpoint's [ListenOptions.Protocols](xref:fundamentals/servers/kestrel/endpoints#listenoptionsprotocols) must be set to `HttpProtocols.Http2`. An endpoint with multiple protocols (for example, `HttpProtocols.Http1AndHttp2`) can't be used without TLS because there's no negotiation. All connections to the unsecured endpoint default to HTTP/1.1, and gRPC calls fail. For more information on enabling HTTP/2 and TLS with Kestrel, see [Kestrel endpoint configuration](xref:fundamentals/servers/kestrel/endpoints). @@ -100,6 +101,7 @@ For more information on enabling HTTP/2 and TLS with Kestrel, see [Kestrel endpo ::: moniker-end ::: moniker range="< aspnetcore-5.0" + ### Configure Kestrel Kestrel gRPC endpoints: @@ -109,7 +111,7 @@ Kestrel gRPC endpoints: #### HTTP/2 -gRPC requires HTTP/2. gRPC for ASP.NET Core validates [HttpRequest.Protocol](xref:Microsoft.AspNetCore.Http.HttpRequest.Protocol*) is `HTTP/2`. +gRPC requires HTTP/2. gRPC for ASP.NET Core validates [HttpRequest.Protocol](xref:Microsoft.AspNetCore.Http.HttpRequest.Protocol%2A) is `HTTP/2`. Kestrel [supports HTTP/2](xref:fundamentals/servers/kestrel#http2-support) on most modern operating systems. Kestrel endpoints are configured to support HTTP/1.1 and HTTP/2 connections by default. @@ -129,7 +131,7 @@ Alternatively, Kestrel endpoints can be configured in *Program.cs*: TLS is used for more than securing communication. The TLS [Application-Layer Protocol Negotiation (ALPN)](https://tools.ietf.org/html/rfc7301#section-3) handshake is used to negotiate the connection protocol between the client and the server when an endpoint supports multiple protocols. This negotiation determines whether the connection uses HTTP/1.1 or HTTP/2. -If an HTTP/2 endpoint is configured without TLS, the endpoint's [ListenOptions.Protocols](xref:fundamentals/servers/kestrel#listenoptionsprotocols) must be set to `HttpProtocols.Http2`. An endpoint with multiple protocols (for example, `HttpProtocols.Http1AndHttp2`) can't be used without TLS because there is no negotiation. All connections to the unsecured endpoint default to HTTP/1.1, and gRPC calls fail. +If an HTTP/2 endpoint is configured without TLS, the endpoint's [ListenOptions.Protocols](xref:fundamentals/servers/kestrel#listenoptionsprotocols) must be set to `HttpProtocols.Http2`. An endpoint with multiple protocols (for example, `HttpProtocols.Http1AndHttp2`) can't be used without TLS because there's no negotiation. All connections to the unsecured endpoint default to HTTP/1.1, and gRPC calls fail. For more information on enabling HTTP/2 and TLS with Kestrel, see [Kestrel endpoint configuration](xref:fundamentals/servers/kestrel#endpoint-configuration). @@ -159,7 +161,7 @@ The gRPC API provides access to some HTTP/2 message data, such as the method, ho [!code-csharp[](~/grpc/aspnetcore/sample/GrcpService/GreeterService.cs?highlight=3-4&name=snippet)] -`ServerCallContext` does not provide full access to `HttpContext` in all ASP.NET APIs. The `GetHttpContext` extension method provides full access to the `HttpContext` representing the underlying HTTP/2 message in ASP.NET APIs: +`ServerCallContext` doesn't provide full access to `HttpContext` in all ASP.NET APIs. The `GetHttpContext` extension method provides full access to the `HttpContext` representing the underlying HTTP/2 message in ASP.NET APIs: [!code-csharp[](~/grpc/aspnetcore/sample/GrcpService/GreeterService2.cs?highlight=6-7&name=snippet)] diff --git a/aspnetcore/host-and-deploy/linux-apache.md b/aspnetcore/host-and-deploy/linux-apache.md index aebbefd7481e..141fcab06dbc 100644 --- a/aspnetcore/host-and-deploy/linux-apache.md +++ b/aspnetcore/host-and-deploy/linux-apache.md @@ -53,7 +53,7 @@ Copy the ASP.NET Core app to the server using a tool that integrates into the or A reverse proxy is a common setup for serving dynamic web apps. The reverse proxy terminates the HTTP request and forwards it to the ASP.NET app. -A proxy server is one which forwards client requests to another server instead of fulfilling requests itself. A reverse proxy forwards to a fixed destination, typically on behalf of arbitrary clients. In this guide, Apache is configured as the reverse proxy running on the same server that Kestrel is serving the ASP.NET Core app. +A proxy server forwards client requests to another server instead of fulfilling requests itself. A reverse proxy forwards to a fixed destination, typically on behalf of arbitrary clients. In this guide, Apache is configured as the reverse proxy running on the same server that Kestrel is serving the ASP.NET Core app. Because requests are forwarded by reverse proxy, use the [Forwarded Headers Middleware](xref:host-and-deploy/proxy-load-balancer) from the [Microsoft.AspNetCore.HttpOverrides](https://www.nuget.org/packages/Microsoft.AspNetCore.HttpOverrides/) package. The middleware updates the `Request.Scheme`, using the `X-Forwarded-Proto` header, so that redirect URIs and other security policies work correctly. @@ -61,7 +61,7 @@ Any component that depends on the scheme, such as authentication, link generatio [!INCLUDE[](~/includes/ForwardedHeaders.md)] -Invoke the method at the top of `Startup.Configure` before calling other middleware. Configure the middleware to forward the `X-Forwarded-For` and `X-Forwarded-Proto` headers: +Invoke the method at the top of `Startup.Configure` before calling other middleware. Configure the middleware to forward the `X-Forwarded-For` and `X-Forwarded-Proto` headers: ```csharp // using Microsoft.AspNetCore.HttpOverrides; @@ -76,7 +76,7 @@ app.UseAuthentication(); If no are specified to the middleware, the default headers to forward are `None`. -Proxies running on loopback addresses (127.0.0.0/8, [::1]), including the standard localhost address (127.0.0.1), are trusted by default. If other trusted proxies or networks within the organization handle requests between the Internet and the web server, add them to the list of or with . The following example adds a trusted proxy server at IP address 10.0.0.100 to the Forwarded Headers Middleware `KnownProxies` in `Startup.ConfigureServices`: +Proxies running on loopback addresses (`127.0.0.0/8, [::1]`), including the standard localhost address (127.0.0.1), are trusted by default. If other trusted proxies or networks within the organization handle requests between the Internet and the web server, add them to the list of or with . The following example adds a trusted proxy server at IP address 10.0.0.100 to the Forwarded Headers Middleware `KnownProxies` in `Startup.ConfigureServices`: ```csharp // using System.Net; @@ -147,15 +147,19 @@ Create a configuration file, named *helloapp.conf*, for the app: ``` ::: moniker range=">= aspnetcore-5.0" -The `VirtualHost` block can appear multiple times, in one or more files on a server. In the preceding configuration file, Apache accepts public traffic on port 80. The domain `www.example.com` is being served, and the `*.example.com` alias resolves to the same website. See [Name-based virtual host support](https://httpd.apache.org/docs/current/vhosts/name-based.html) for more information. Requests are proxied at the root to port 5000 of the server at 127.0.0.1. For bi-directional communication, `ProxyPass` and `ProxyPassReverse` are required. To change Kestrel's IP/port, see [Kestrel: Endpoint configuration](xref:fundamentals/servers/kestrel/endpoints). + +The `VirtualHost` block can appear multiple times, in one or more files on a server. In the preceding configuration file, Apache accepts public traffic on port 80. The domain `www.example.com` is being served, and the `*.example.com` alias resolves to the same website. For more information, see [Name-based virtual host support](https://httpd.apache.org/docs/current/vhosts/name-based.html). Requests are proxied at the root to port 5000 of the server at 127.0.0.1. For bi-directional communication, `ProxyPass` and `ProxyPassReverse` are required. To change Kestrel's IP/port, see [Kestrel: Endpoint configuration](xref:fundamentals/servers/kestrel/endpoints). + ::: moniker-end ::: moniker range="< aspnetcore-5.0" -The `VirtualHost` block can appear multiple times, in one or more files on a server. In the preceding configuration file, Apache accepts public traffic on port 80. The domain `www.example.com` is being served, and the `*.example.com` alias resolves to the same website. See [Name-based virtual host support](https://httpd.apache.org/docs/current/vhosts/name-based.html) for more information. Requests are proxied at the root to port 5000 of the server at 127.0.0.1. For bi-directional communication, `ProxyPass` and `ProxyPassReverse` are required. To change Kestrel's IP/port, see [Kestrel: Endpoint configuration](xref:fundamentals/servers/kestrel#endpoint-configuration). + +The `VirtualHost` block can appear multiple times, in one or more files on a server. In the preceding configuration file, Apache accepts public traffic on port 80. The domain `www.example.com` is being served, and the `*.example.com` alias resolves to the same website. For more information, see [Name-based virtual host support](https://httpd.apache.org/docs/current/vhosts/name-based.html). Requests are proxied at the root to port 5000 of the server at 127.0.0.1. For bi-directional communication, `ProxyPass` and `ProxyPassReverse` are required. To change Kestrel's IP/port, see [Kestrel: Endpoint configuration](xref:fundamentals/servers/kestrel#endpoint-configuration). + ::: moniker-end > [!WARNING] -> Failure to specify a proper [ServerName directive](https://httpd.apache.org/docs/current/mod/core.html#servername) in the **VirtualHost** block exposes your app to security vulnerabilities. Subdomain wildcard binding (for example, `*.example.com`) doesn't pose this security risk if you control the entire parent domain (as opposed to `*.com`, which is vulnerable). See [rfc7230 section-5.4](https://tools.ietf.org/html/rfc7230#section-5.4) for more information. +> Failure to specify a proper [ServerName directive](https://httpd.apache.org/docs/current/mod/core.html#servername) in the **VirtualHost** block exposes your app to security vulnerabilities. Subdomain wildcard binding (for example, `*.example.com`) doesn't pose this security risk if you control the entire parent domain (as opposed to `*.com`, which is vulnerable). For more information, see [rfc7230 section-5.4](https://tools.ietf.org/html/rfc7230#section-5.4). Logging can be configured per `VirtualHost` using `ErrorLog` and `CustomLog` directives. `ErrorLog` is the location where the server logs errors, and `CustomLog` sets the filename and format of log file. In this case, this is where request information is logged. There's one line for each request. @@ -174,7 +178,7 @@ sudo systemctl enable httpd ## Monitor the app -Apache is now setup to forward requests made to `http://localhost:80` to the ASP.NET Core app running on Kestrel at `http://127.0.0.1:5000`. However, Apache isn't set up to manage the Kestrel process. Use *systemd* and create a service file to start and monitor the underlying web app. *systemd* is an init system that provides many powerful features for starting, stopping, and managing processes. +Apache is now set up to forward requests made to `http://localhost:80` to the ASP.NET Core app running on Kestrel at `http://127.0.0.1:5000`. However, Apache isn't set up to manage the Kestrel process. Use *systemd* and create a service file to start and monitor the underlying web app. *systemd* is an init system that provides many powerful features for starting, stopping, and managing processes. ### Create the service file @@ -225,6 +229,7 @@ systemd-escape "" Colon (`:`) separators aren't supported in environment variable names. Use a double underscore (`__`) in place of a colon. The [Environment Variables configuration provider](xref:fundamentals/configuration/index#environment-variables-configuration-provider) converts double-underscores into colons when environment variables are read into configuration. In the following example, the connection string key `ConnectionStrings:DefaultConnection` is set into the service definition file as `ConnectionStrings__DefaultConnection`: ::: moniker-end + ::: moniker range="< aspnetcore-3.0" Colon (`:`) separators aren't supported in environment variable names. Use a double underscore (`__`) in place of a colon. The [Environment Variables configuration provider](xref:fundamentals/configuration/index#environment-variables) converts double-underscores into colons when environment variables are read into configuration. In the following example, the connection string key `ConnectionStrings:DefaultConnection` is set into the service definition file as `ConnectionStrings__DefaultConnection`: @@ -305,7 +310,7 @@ To configure data protection to persist and encrypt the key ring, see: sudo yum install firewalld -y ``` -Use `firewalld` to open only the ports needed for the app. In this case, port 80 and 443 are used. The following commands permanently set ports 80 and 443 to open: +Use `firewalld` to open only the ports needed for the app. In this case, ports 80 and 443 are used. The following commands permanently set ports 80 and 443 to open: ```bash sudo firewall-cmd --add-port=80/tcp --permanent @@ -340,12 +345,17 @@ The [dotnet run](/dotnet/core/tools/dotnet-run) command uses the app's *Properti Configure the app to use a certificate in development for the `dotnet run` command or development environment (F5 or Ctrl+F5 in Visual Studio Code) using one of the following approaches: ::: moniker range=">= aspnetcore-5.0" + * [Replace the default certificate from configuration](xref:fundamentals/servers/kestrel/endpoints#configuration) (*Recommended*) * [KestrelServerOptions.ConfigureHttpsDefaults](xref:fundamentals/servers/kestrel/endpoints#configurehttpsdefaultsactionhttpsconnectionadapteroptions) + ::: moniker-end + ::: moniker range="< aspnetcore-5.0" + * [Replace the default certificate from configuration](xref:fundamentals/servers/kestrel#configuration) (*Recommended*) * [KestrelServerOptions.ConfigureHttpsDefaults](xref:fundamentals/servers/kestrel#configurehttpsdefaultsactionhttpsconnectionadapteroptions) + ::: moniker-end **Configure the reverse proxy for secure (HTTPS) client connections** @@ -412,7 +422,7 @@ After upgrading the shared framework on the server, restart the ASP.NET Core app ### Additional headers -In order to secure against malicious attacks, there are a few headers that should either be modified or added. Ensure that the `mod_headers` module is installed: +To secure against malicious attacks, there are a few headers that should either be modified or added. Ensure that the `mod_headers` module is installed: ```bash sudo yum install mod_headers @@ -448,7 +458,7 @@ Add the line `Header set X-Content-Type-Options "nosniff"`. Save the file. Resta ### Load Balancing -This example shows how to setup and configure Apache on CentOS 7 and Kestrel on the same instance machine. In order to not have a single point of failure; using *mod_proxy_balancer* and modifying the **VirtualHost** would allow for managing multiple instances of the web apps behind the Apache proxy server. +This example shows how to setup and configure Apache on CentOS 7 and Kestrel on the same instance machine. To not have a single point of failure; using *mod_proxy_balancer* and modifying the **VirtualHost** would allow for managing multiple instances of the web apps behind the Apache proxy server. ```bash sudo yum install mod_proxy_balancer diff --git a/aspnetcore/host-and-deploy/linux-nginx.md b/aspnetcore/host-and-deploy/linux-nginx.md index 3fbfa35fa709..c9e4bd4f6237 100644 --- a/aspnetcore/host-and-deploy/linux-nginx.md +++ b/aspnetcore/host-and-deploy/linux-nginx.md @@ -1,7 +1,7 @@ --- title: Host ASP.NET Core on Linux with Nginx author: rick-anderson -description: Learn how to setup Nginx as a reverse proxy on Ubuntu 16.04 to forward HTTP traffic to an ASP.NET Core web app running on Kestrel. +description: Learn how to set up Nginx as a reverse proxy on Ubuntu 16.04 to forward HTTP traffic to an ASP.NET Core web app running on Kestrel. monikerRange: '>= aspnetcore-2.1' ms.author: riande ms.custom: mvc @@ -80,7 +80,7 @@ Because requests are forwarded by reverse proxy, use the [Forwarded Headers Midd [!INCLUDE[](~/includes/ForwardedHeaders.md)] -Invoke the method at the top of `Startup.Configure` before calling other middleware. Configure the middleware to forward the `X-Forwarded-For` and `X-Forwarded-Proto` headers: +Invoke the method at the top of `Startup.Configure` before calling other middleware. Configure the middleware to forward the `X-Forwarded-For` and `X-Forwarded-Proto` headers: ```csharp using Microsoft.AspNetCore.HttpOverrides; @@ -97,7 +97,7 @@ app.UseAuthentication(); If no are specified to the middleware, the default headers to forward are `None`. -Proxies running on loopback addresses (`127.0.0.0/8`, `[::1]`), including the standard localhost address (`127.0.0.1`), are trusted by default. If other trusted proxies or networks within the organization handle requests between the Internet and the web server, add them to the list of or with . The following example adds a trusted proxy server at IP address 10.0.0.100 to the Forwarded Headers Middleware `KnownProxies` in `Startup.ConfigureServices`: +Proxies running on loopback addresses (`127.0.0.0/8`, `[::1]`), including the standard localhost address (`127.0.0.1`), are trusted by default. If other trusted proxies or networks within the organization handle requests between the Internet and the web server, add them to the list of or with . The following example adds a trusted proxy server at IP address 10.0.0.100 to the Forwarded Headers Middleware `KnownProxies` in `Startup.ConfigureServices`: ```csharp using System.Net; @@ -129,7 +129,7 @@ Verify a browser displays the default landing page for Nginx. The landing page i ### Configure Nginx -To configure Nginx as a reverse proxy to forward HTTP requests to your ASP.NET Core app, modify `/etc/nginx/sites-available/default`. Open it in a text editor, and replace the contents with the following: +To configure Nginx as a reverse proxy to forward HTTP requests to your ASP.NET Core app, modify `/etc/nginx/sites-available/default`. Open it in a text editor, and replace the contents with the following snippet: ```nginx server { @@ -148,9 +148,9 @@ server { } ``` -If the app is a SignalR or Blazor Server app see and respectively for more information. +If the app is a SignalR or Blazor Server app, see and respectively for more information. -When no `server_name` matches, Nginx uses the default server. If no default server is defined, the first server in the configuration file is the default server. As a best practice, add a specific default server which returns a status code of 444 in your configuration file. A default server configuration example is: +When no `server_name` matches, Nginx uses the default server. If no default server is defined, the first server in the configuration file is the default server. As a best practice, add a specific default server that returns a status code of 444 in your configuration file. A default server configuration example is: ```nginx server { @@ -161,15 +161,19 @@ server { ``` ::: moniker range=">= aspnetcore-5.0" -With the preceding configuration file and default server, Nginx accepts public traffic on port 80 with host header `example.com` or `*.example.com`. Requests not matching these hosts won't get forwarded to Kestrel. Nginx forwards the matching requests to Kestrel at `http://localhost:5000`. See [How nginx processes a request](https://nginx.org/docs/http/request_processing.html) for more information. To change Kestrel's IP/port, see [Kestrel: Endpoint configuration](xref:fundamentals/servers/kestrel/endpoints). + +With the preceding configuration file and default server, Nginx accepts public traffic on port 80 with host header `example.com` or `*.example.com`. Requests not matching these hosts won't get forwarded to Kestrel. Nginx forwards the matching requests to Kestrel at `http://localhost:5000`. For more information, see [How nginx processes a request](https://nginx.org/docs/http/request_processing.html). To change Kestrel's IP/port, see [Kestrel: Endpoint configuration](xref:fundamentals/servers/kestrel/endpoints). + ::: moniker-end ::: moniker range="< aspnetcore-5.0" -With the preceding configuration file and default server, Nginx accepts public traffic on port 80 with host header `example.com` or `*.example.com`. Requests not matching these hosts won't get forwarded to Kestrel. Nginx forwards the matching requests to Kestrel at `http://localhost:5000`. See [How nginx processes a request](https://nginx.org/docs/http/request_processing.html) for more information. To change Kestrel's IP/port, see [Kestrel: Endpoint configuration](xref:fundamentals/servers/kestrel#endpoint-configuration). + +With the preceding configuration file and default server, Nginx accepts public traffic on port 80 with host header `example.com` or `*.example.com`. Requests not matching these hosts won't get forwarded to Kestrel. Nginx forwards the matching requests to Kestrel at `http://localhost:5000`. For more information, see [How nginx processes a request](https://nginx.org/docs/http/request_processing.html). To change Kestrel's IP/port, see [Kestrel: Endpoint configuration](xref:fundamentals/servers/kestrel#endpoint-configuration). + ::: moniker-end > [!WARNING] -> Failure to specify a proper [server_name directive](https://nginx.org/docs/http/server_names.html) exposes your app to security vulnerabilities. Subdomain wildcard binding (for example, `*.example.com`) doesn't pose this security risk if you control the entire parent domain (as opposed to `*.com`, which is vulnerable). See [rfc7230 section-5.4](https://tools.ietf.org/html/rfc7230#section-5.4) for more information. +> Failure to specify a proper [server_name directive](https://nginx.org/docs/http/server_names.html) exposes your app to security vulnerabilities. Subdomain wildcard binding (for example, `*.example.com`) doesn't pose this security risk if you control the entire parent domain (as opposed to `*.com`, which is vulnerable). For more information, see [rfc7230 section-5.4](https://tools.ietf.org/html/rfc7230#section-5.4). Once the Nginx configuration is established, run `sudo nginx -t` to verify the syntax of the configuration files. If the configuration file test is successful, force Nginx to pick up the changes by running `sudo nginx -s reload`. @@ -178,13 +182,13 @@ To directly run the app on the server: 1. Navigate to the app's directory. 1. Run the app: `dotnet `, where `app_assembly.dll` is the assembly file name of the app. -If the app runs on the server but fails to respond over the Internet, check the server's firewall and confirm that port 80 is open. If using an Azure Ubuntu VM, add a Network Security Group (NSG) rule that enables inbound port 80 traffic. There's no need to enable an outbound port 80 rule, as the outbound traffic is automatically granted when the inbound rule is enabled. +If the app runs on the server but fails to respond over the Internet, check the server's firewall and confirm port 80 is open. If using an Azure Ubuntu VM, add a Network Security Group (NSG) rule that enables inbound port 80 traffic. There's no need to enable an outbound port 80 rule, as the outbound traffic is automatically granted when the inbound rule is enabled. -When done testing the app, shut the app down with `Ctrl+C` at the command prompt. +When done testing the app, shut down the app with Ctrl + C at the command prompt. ## Monitor the app -The server is setup to forward requests made to `http://:80` on to the ASP.NET Core app running on Kestrel at `http://127.0.0.1:5000`. However, Nginx isn't set up to manage the Kestrel process. `systemd` can be used to create a service file to start and monitor the underlying web app. `systemd` is an init system that provides many powerful features for starting, stopping, and managing processes. +The server is set up to forward requests made to `http://:80` on to the ASP.NET Core app running on Kestrel at `http://127.0.0.1:5000`. However, Nginx isn't set up to manage the Kestrel process. `systemd` can be used to create a service file to start and monitor the underlying web app. `systemd` is an init system that provides many powerful features for starting, stopping, and managing processes. ### Create the service file @@ -194,7 +198,7 @@ Create the service definition file: sudo nano /etc/systemd/system/kestrel-helloapp.service ``` -The following is an example service file for the app: +The following example is a service file for the app: ```ini [Unit] @@ -287,7 +291,7 @@ Since the web app using Kestrel is managed using `systemd`, all events and proce sudo journalctl -fu kestrel-helloapp.service ``` -For further filtering, time options such as `--since today`, `--until 1 hour ago` or a combination of these can reduce the amount of entries returned. +For further filtering, time options such as `--since today`, `--until 1 hour ago`, or a combination of these can reduce the number of entries returned. ```bash sudo journalctl -fu kestrel-helloapp.service --since "2016-10-18" --until "2016-10-18 04:00" @@ -324,11 +328,11 @@ Proxy server default settings typically limit request header fields to 4 K or 8 ### Enable AppArmor -Linux Security Modules (LSM) is a framework that's part of the Linux kernel since Linux 2.6. LSM supports different implementations of security modules. [AppArmor](https://wiki.ubuntu.com/AppArmor) is a LSM that implements a Mandatory Access Control system which allows confining the program to a limited set of resources. Ensure AppArmor is enabled and properly configured. +Linux Security Modules (LSM) is a framework that's part of the Linux kernel since Linux 2.6. LSM supports different implementations of security modules. [AppArmor](https://wiki.ubuntu.com/AppArmor) is an LSM that implements a Mandatory Access Control system, which allows confining the program to a limited set of resources. Ensure AppArmor is enabled and properly configured. ### Configure the firewall -Close off all external ports that are not in use. Uncomplicated firewall (ufw) provides a front end for `iptables` by providing a CLI for configuring the firewall. +Close off all external ports that aren't in use. Uncomplicated firewall (ufw) provides a front end for `iptables` by providing a CLI for configuring the firewall. > [!WARNING] > A firewall will prevent access to the whole system if not configured correctly. Failure to specify the correct SSH port will effectively lock you out of the system if you are using SSH to connect to it. The default port is 22. For more information, see the [introduction to ufw](https://help.ubuntu.com/community/UFW) and the [manual](https://manpages.ubuntu.com/manpages/bionic/man8/ufw.8.html). @@ -364,25 +368,29 @@ Configure the server with additional required modules. Consider using a web app **Configure the app for secure (HTTPS) local connections** -The [dotnet run](/dotnet/core/tools/dotnet-run) command uses the app's `Properties/launchSettings.json` file, which configures the app to listen on the URLs provided by the `applicationUrl` property (for example, `https://localhost:5001;http://localhost:5000`). +The [dotnet run](/dotnet/core/tools/dotnet-run) command uses the app's *Properties/launchSettings.json* file, which configures the app to listen on the URLs provided by the `applicationUrl` property. For example, `https://localhost:5001;http://localhost:5000`. Configure the app to use a certificate in development for the `dotnet run` command or development environment (F5 or Ctrl+F5 in Visual Studio Code) using one of the following approaches: ::: moniker range=">= aspnetcore-5.0" + * [Replace the default certificate from configuration](xref:fundamentals/servers/kestrel/endpoints#configuration) (*Recommended*) * [KestrelServerOptions.ConfigureHttpsDefaults](xref:fundamentals/servers/kestrel/endpoints#configurehttpsdefaultsactionhttpsconnectionadapteroptions) + ::: moniker-end ::: moniker range="< aspnetcore-5.0" + * [Replace the default certificate from configuration](xref:fundamentals/servers/kestrel#configuration) (*Recommended*) * [KestrelServerOptions.ConfigureHttpsDefaults](xref:fundamentals/servers/kestrel#configurehttpsdefaultsactionhttpsconnectionadapteroptions) + ::: moniker-end **Configure the reverse proxy for secure (HTTPS) client connections** -* Configure the server to listen to HTTPS traffic on port `443` by specifying a valid certificate issued by a trusted Certificate Authority (CA). +* Configure the server to listen to HTTPS traffic on port 443 by specifying a valid certificate issued by a trusted Certificate Authority (CA). -* Harden the security by employing some of the practices depicted in the following `/etc/nginx/nginx.conf` file. Examples include choosing a stronger cipher and redirecting all traffic over HTTP to HTTPS. +* Harden the security by employing some of the practices depicted in the following */etc/nginx/nginx.conf* file. Examples include choosing a stronger cipher and redirecting all traffic over HTTP to HTTPS. > [!NOTE] > For development environments, we recommend using temporary redirects (302) rather than permanent redirects (301). Link caching can cause unstable behavior in development environments. @@ -396,11 +404,11 @@ Configure the app to use a certificate in development for the `dotnet run` comma * Don't add the HSTS header. * Choose a short `max-age` value. -Add the `/etc/nginx/proxy.conf` configuration file: +Add the */etc/nginx/proxy.conf* configuration file: [!code-nginx[](linux-nginx/proxy.conf)] -**Replace** the contents of the `/etc/nginx/nginx.conf` configuration file with the following file. The example contains both `http` and `server` sections in one configuration file. +**Replace** the contents of the */etc/nginx/nginx.conf* configuration file with the following file. The example contains both `http` and `server` sections in one configuration file. [!code-nginx[](linux-nginx/nginx.conf?highlight=2)] @@ -413,7 +421,7 @@ Add the `/etc/nginx/proxy.conf` configuration file: To mitigate clickjacking attacks: -1. Edit the `nginx.conf` file: +1. Edit the *nginx.conf* file: ```bash sudo nano /etc/nginx/nginx.conf @@ -428,7 +436,7 @@ To mitigate clickjacking attacks: This header prevents most browsers from MIME-sniffing a response away from the declared content type, as the header instructs the browser not to override the response content type. With the `nosniff` option, if the server says the content is `text/html`, the browser renders it as `text/html`. -1. Edit the `nginx.conf` file: +1. Edit the *nginx.conf* file: ```bash sudo nano /etc/nginx/nginx.conf diff --git a/aspnetcore/host-and-deploy/windows-service.md b/aspnetcore/host-and-deploy/windows-service.md index e62cb208ac5a..1eb155f72aa4 100644 --- a/aspnetcore/host-and-deploy/windows-service.md +++ b/aspnetcore/host-and-deploy/windows-service.md @@ -222,10 +222,15 @@ For additional URL and port configuration approaches, see the relevant server ar ::: moniker-end ::: moniker range=">= aspnetcore-5.0" + * + ::: moniker-end + ::: moniker range="< aspnetcore-5.0 >= aspnetcore-3.0" + * + ::: moniker-end ::: moniker range=">= aspnetcore-3.0" @@ -239,25 +244,25 @@ The preceding guidance covers support for HTTPS endpoints. For example, configur ## Current directory and content root -The current working directory returned by calling for a Windows Service is the *C:\\WINDOWS\\system32* folder. The *system32* folder isn't a suitable location to store a service's files (for example, settings files). Use one of the following approaches to maintain and access a service's assets and settings files. +The current working directory returned by calling for a Windows Service is the *C:\\WINDOWS\\system32* folder. The *system32* folder isn't a suitable location to store a service's files (for example, settings files). Use one of the following approaches to maintain and access a service's assets and settings files. ### Use ContentRootPath or ContentRootFileProvider Use [IHostEnvironment.ContentRootPath](xref:Microsoft.Extensions.Hosting.IHostEnvironment.ContentRootPath) or to locate an app's resources. -When the app runs as a service, sets the to [AppContext.BaseDirectory](xref:System.AppContext.BaseDirectory). +When the app runs as a service, sets the to [AppContext.BaseDirectory](xref:System.AppContext.BaseDirectory). The app's default settings files, *appsettings.json* and *appsettings.{Environment}.json*, are loaded from the app's content root by calling [CreateDefaultBuilder during host construction](xref:fundamentals/host/generic-host#set-up-a-host). -For other settings files loaded by developer code in , there's no need to call . In the following example, the *custom_settings.json* file exists in the app's content root and is loaded without explicitly setting a base path: +For other settings files loaded by developer code in , there's no need to call . In the following example, the *custom_settings.json* file exists in the app's content root and is loaded without explicitly setting a base path: [!code-csharp[](windows-service/samples_snapshot/CustomSettingsExample.cs?highlight=13)] -Don't attempt to use to obtain a resource path because a Windows Service app returns the *C:\\WINDOWS\\system32* folder as its current directory. +Don't attempt to use to obtain a resource path because a Windows Service app returns the *C:\\WINDOWS\\system32* folder as its current directory. ### Store a service's files in a suitable location on disk -Specify an absolute path with when using an to the folder containing the files. +Specify an absolute path with when using an to the folder containing the files. ## Troubleshoot diff --git a/aspnetcore/security/authentication/certauth.md b/aspnetcore/security/authentication/certauth.md index 2897b1b6723b..70789de2cb45 100644 --- a/aspnetcore/security/authentication/certauth.md +++ b/aspnetcore/security/authentication/certauth.md @@ -136,37 +136,37 @@ The handler has two events: * Determining if the certificate is known to your services. * Constructing your own principal. Consider the following example in `Startup.ConfigureServices`: -```csharp -services.AddAuthentication( - CertificateAuthenticationDefaults.AuthenticationScheme) - .AddCertificate(options => - { - options.Events = new CertificateAuthenticationEvents + ```csharp + services.AddAuthentication( + CertificateAuthenticationDefaults.AuthenticationScheme) + .AddCertificate(options => { - OnCertificateValidated = context => + options.Events = new CertificateAuthenticationEvents { - var claims = new[] + OnCertificateValidated = context => { - new Claim( - ClaimTypes.NameIdentifier, - context.ClientCertificate.Subject, - ClaimValueTypes.String, - context.Options.ClaimsIssuer), - new Claim(ClaimTypes.Name, - context.ClientCertificate.Subject, - ClaimValueTypes.String, - context.Options.ClaimsIssuer) - }; - - context.Principal = new ClaimsPrincipal( - new ClaimsIdentity(claims, context.Scheme.Name)); - context.Success(); - - return Task.CompletedTask; - } - }; - }); -``` + var claims = new[] + { + new Claim( + ClaimTypes.NameIdentifier, + context.ClientCertificate.Subject, + ClaimValueTypes.String, + context.Options.ClaimsIssuer), + new Claim(ClaimTypes.Name, + context.ClientCertificate.Subject, + ClaimValueTypes.String, + context.Options.ClaimsIssuer) + }; + + context.Principal = new ClaimsPrincipal( + new ClaimsIdentity(claims, context.Scheme.Name)); + context.Success(); + + return Task.CompletedTask; + } + }; + }); + ``` If you find the inbound certificate doesn't meet your extra validation, call `context.Fail("failure reason")` with a failure reason. @@ -285,7 +285,7 @@ public void ConfigureServices(IServiceCollection services) options.HeaderConverter = (headerValue) => { X509Certificate2 clientCertificate = null; - + if(!string.IsNullOrWhiteSpace(headerValue)) { byte[] bytes = StringToByteArray(headerValue); @@ -623,6 +623,7 @@ ASP.NET Core 5 preview 7 and later adds more convenient support for optional cli The following approach supports optional client certificates: ::: moniker range=">= aspnetcore-5.0" + * Set up binding for the domain and subdomain: * For example, set up bindings on `contoso.com` and `myClient.contoso.com`. The `contoso.com` host doesn't require a client certificate but `myClient.contoso.com` does. * For more information, see: @@ -634,8 +635,11 @@ The following approach supports optional client certificates: * [Hosting IIS](xref:host-and-deploy/iis/index#create-the-iis-site) * [Configure security on IIS](/iis/manage/configuring-security/how-to-set-up-ssl-on-iis#configure-ssl-settings-2) * Http.Sys: [Configure Windows Server](xref:fundamentals/servers/httpsys#configure-windows-server) + ::: moniker-end + ::: moniker range="< aspnetcore-5.0" + * Set up binding for the domain and subdomain: * For example, set up bindings on `contoso.com` and `myClient.contoso.com`. The `contoso.com` host doesn't require a client certificate but `myClient.contoso.com` does. * For more information, see: @@ -647,7 +651,9 @@ The following approach supports optional client certificates: * [Hosting IIS](xref:host-and-deploy/iis/index#create-the-iis-site) * [Configure security on IIS](/iis/manage/configuring-security/how-to-set-up-ssl-on-iis#configure-ssl-settings-2) * Http.Sys: [Configure Windows Server](xref:fundamentals/servers/httpsys#configure-windows-server) + ::: moniker-end + * For requests to the web app that require a client certificate and don't have one: * Redirect to the same page using the client certificate protected subdomain. * For example, redirect to `myClient.contoso.com/requestedPage`. Because the request to `myClient.contoso.com/requestedPage` is a different hostname than `contoso.com/requestedPage`, the client establishes a different connection and the client certificate is provided.