HomeContact

Dot Net 6 Kestrel Linux Configuration

By Shady Nagy
Published in dotnet
December 01, 2021
1 min read
Dot Net 6 Kestrel Linux Configuration

Table Of Contents

01
Introduction
02
Method 1: Configure Kestrel in Program.cs
03
Method 2: Configure Kestrel in appsettings.json
04
Conclusion
05
Further Reading
06
Feedback and Questions

Introduction

In this post, we will discuss how to configure the Kestrel server in .NET 6 using two different methods: the Program.cs file and the appsettings.json file. By following these steps, you can easily customize the Kestrel server settings for your application.

Method 1: Configure Kestrel in Program.cs

To change the Kestrel configurations using the Program.cs file in .NET 6, you can do the following:

builder.WebHost.ConfigureKestrel(
options => {
// HTTP 6000
options.ListenLocalhost(6000);
// HTTPS 6001
options.ListenLocalhost(6001, httpsBuilder =>
{
httpsBuilder.UseHttps();
});
});

Method 2: Configure Kestrel in appsettings.json

An alternative way to configure the Kestrel server is by using the appsettings.json file. You can add the following JSON configuration to the file:

{
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://localhost:6000"
},
"Https": {
"Url": "https://localhost:6001",
"Certificate": {
"Path": "path/to/your/certificate.pfx",
"Password": "your-certificate-password"
}
}
}
}
}

In this example, the Kestrel server is configured to listen on HTTP port 6000 and HTTPS port 6001.

Conclusion

Kestrel is a powerful and flexible web server for .NET Core applications, and configuring it correctly is crucial for the performance and security of your web apps. By modifying the Program.cs or appsettings.json file in your .NET 6 project, you can easily configure Kestrel to listen on specific ports for HTTP and HTTPS connections.

Further Reading

For more information on Kestrel and .NET 6, please refer to the following resources:

  • Official Kestrel documentation
  • .NET 6 announcement

Feedback and Questions

We’d love to hear your feedback on this tutorial! If you have any questions or suggestions for improvement, please don’t hesitate to reach out. You can leave a comment below, or you can contact us through the following channels:

  1. Email: shady@shadynagy.com
  2. Twitter: @ShadyNagy_
  3. LinkedIn: Shady Nagy
  4. GitHub: ShadyNagy

We’ll do our best to address any questions or concerns you may have. We look forward to hearing from you and helping you make the most of Kestrel in your .NET 6 projects!


Tags

#microsoft#dotnet6#dotnet#dotnet core#Kestrel#C##csharp#linux

Share


Previous Article
Exclude C# Integration Tests on GitHub Actions
Shady Nagy

Shady Nagy

Software Innovation Architect

Topics

AI
Angular
dotnet
GatsbyJS
Github
Linux
Oracle
MS SQL

Related Posts

Unraveling Performance Bottlenecks in .NET Applications A Deep Dive with Code Examples
Unraveling Performance Bottlenecks in .NET Applications A Deep Dive with Code Examples
December 31, 2023
1 min

Quick Links

Contact Us

Social Media