Skip to content

Server & SSL Settings

This page covers the web server configuration including SSL/HTTPS settings and Kestrel server options.

SSL Configuration

The Ssl section enables HTTPS support and related security features.

json
{
  "Ssl": {
    "Enabled": false,
    "HttpsRedirection": true,
    "UseHsts": true
  }
}

Settings Reference

SettingTypeDefaultDescription
EnabledboolfalseEnable Kestrel HTTPS configuration. See UseKestrelHttpsConfiguration.
HttpsRedirectionbooltrueRedirect HTTP requests to HTTPS. See UseHttpsRedirection.
UseHstsbooltrueAdd the Strict-Transport-Security header (HSTS). See UseHsts.

Enabling HTTPS

To enable HTTPS, set Ssl.Enabled to true and configure your certificates in the Kestrel section:

json
{
  "Ssl": {
    "Enabled": true,
    "HttpsRedirection": true,
    "UseHsts": true
  }
}

HTTPS Redirection

When HttpsRedirection is true, all HTTP requests are automatically redirected to HTTPS. This ensures users always use the secure connection.

HTTP Strict Transport Security (HSTS)

When UseHsts is true, the server sends the Strict-Transport-Security header, instructing browsers to only access the site over HTTPS for a specified period.

WARNING

HSTS should only be enabled in production environments. It can cause issues during development if you don't have valid certificates configured.

Kestrel Configuration

The Kestrel section configures the underlying web server, including endpoints, certificates, and connection limits.

json
{
  "Kestrel": {
    "Endpoints": {
      "Http": {
        "Url": "http://localhost:5000"
      },
      "Https": {
        "Url": "https://localhost:5001",
        "Certificate": {
          "Path": "/path/to/certificate.pfx",
          "Password": "{CERT_PASSWORD}"
        }
      }
    }
  }
}

For complete Kestrel configuration options, see the Microsoft documentation.

Certificate Configuration

Kestrel supports multiple ways to configure SSL certificates:

PFX File

json
{
  "Kestrel": {
    "Endpoints": {
      "Https": {
        "Url": "https://localhost:5001",
        "Certificate": {
          "Path": "/path/to/certificate.pfx",
          "Password": "{CERT_PASSWORD}"
        }
      }
    }
  }
}

PEM/CRT with Key File

json
{
  "Kestrel": {
    "Endpoints": {
      "Https": {
        "Url": "https://localhost:5001",
        "Certificate": {
          "Path": "/path/to/certificate.pem",
          "KeyPath": "/path/to/private.key",
          "Password": "{KEY_PASSWORD}"
        }
      }
    }
  }
}

Certificate Store (Windows)

json
{
  "Kestrel": {
    "Endpoints": {
      "Https": {
        "Url": "https://localhost:5001",
        "Certificate": {
          "Subject": "localhost",
          "Store": "My",
          "Location": "CurrentUser",
          "AllowInvalid": false
        }
      }
    }
  }
}

Default Certificate

You can define a default certificate used by all HTTPS endpoints:

json
{
  "Kestrel": {
    "Endpoints": {
      "Https": {
        "Url": "https://localhost:5001"
      }
    },
    "Certificates": {
      "Default": {
        "Path": "/path/to/certificate.pfx",
        "Password": "{CERT_PASSWORD}"
      }
    }
  }
}

Connection Limits

Configure connection and request limits to protect your server:

json
{
  "Kestrel": {
    "Limits": {
      "MaxConcurrentConnections": 100,
      "MaxConcurrentUpgradedConnections": 100,
      "MaxRequestBodySize": 30000000,
      "MaxRequestBufferSize": 1048576,
      "MaxRequestHeaderCount": 100,
      "MaxRequestHeadersTotalSize": 32768,
      "MaxRequestLineSize": 8192,
      "MaxResponseBufferSize": 65536,
      "KeepAliveTimeout": "00:02:00",
      "RequestHeadersTimeout": "00:00:30"
    }
  }
}

Limits Reference

SettingDefaultDescription
MaxConcurrentConnectionsnull (unlimited)Maximum number of open connections.
MaxConcurrentUpgradedConnectionsnull (unlimited)Maximum number of upgraded connections (e.g., WebSockets).
MaxRequestBodySize30,000,000 (~28.6 MB)Maximum request body size in bytes.
MaxRequestBufferSize1,048,576 (1 MB)Maximum size of the request buffer.
MaxRequestHeaderCount100Maximum number of request headers.
MaxRequestHeadersTotalSize32,768 (32 KB)Maximum total size of request headers.
MaxRequestLineSize8,192 (8 KB)Maximum size of the request line.
MaxResponseBufferSize65,536 (64 KB)Maximum size of the response buffer.
KeepAliveTimeout2 minutesTimeout for keep-alive connections.
RequestHeadersTimeout30 secondsTimeout for receiving request headers.

HTTP/2 Settings

Configure HTTP/2 specific options:

json
{
  "Kestrel": {
    "Limits": {
      "Http2": {
        "MaxStreamsPerConnection": 100,
        "HeaderTableSize": 4096,
        "MaxFrameSize": 16384,
        "MaxRequestHeaderFieldSize": 8192,
        "InitialConnectionWindowSize": 65535,
        "InitialStreamWindowSize": 65535,
        "KeepAlivePingDelay": "00:00:30",
        "KeepAlivePingTimeout": "00:01:00",
        "KeepAlivePingPolicy": "WithActiveRequests"
      }
    }
  }
}

HTTP/3 Settings

Configure HTTP/3 (QUIC) specific options:

json
{
  "Kestrel": {
    "Limits": {
      "Http3": {
        "MaxRequestHeaderFieldSize": 8192
      }
    }
  }
}

Additional Kestrel Options

json
{
  "Kestrel": {
    "DisableStringReuse": false,
    "AllowAlternateSchemes": false,
    "AllowSynchronousIO": false,
    "AllowResponseHeaderCompression": true,
    "AddServerHeader": true,
    "AllowHostHeaderOverride": false
  }
}
SettingDefaultDescription
DisableStringReusefalseDisable string reuse optimization for debugging.
AllowAlternateSchemesfalseAllow alternate URI schemes in requests.
AllowSynchronousIOfalseAllow synchronous I/O operations (not recommended).
AllowResponseHeaderCompressiontrueEnable response header compression for HTTP/2.
AddServerHeadertrueAdd the Server header to responses.
AllowHostHeaderOverridefalseAllow the Host header to be overridden.

Complete Example

Here's a production-ready configuration with HTTPS enabled:

json
{
  "Urls": "http://localhost:5000;https://localhost:5001",
  "Ssl": {
    "Enabled": true,
    "HttpsRedirection": true,
    "UseHsts": true
  },
  "Kestrel": {
    "Endpoints": {
      "Http": {
        "Url": "http://0.0.0.0:5000"
      },
      "Https": {
        "Url": "https://0.0.0.0:5001",
        "Certificate": {
          "Path": "/etc/ssl/certs/myapp.pfx",
          "Password": "{CERT_PASSWORD}"
        }
      }
    },
    "Limits": {
      "MaxConcurrentConnections": 1000,
      "MaxRequestBodySize": 52428800,
      "KeepAliveTimeout": "00:02:00",
      "RequestHeadersTimeout": "00:00:30"
    }
  }
}

Next Steps

Released under the MIT License.