Configure ASP.NET Core ports with Kestrel (Linux)

This is something that I have to google all the time. So let’s write it down as a blog-post! 🙂

The following assumes that we are running ASP.NET Core on Linux, without IIS. Tested with .NET 5

Source: StackOverflow

Options

As dotnet CLI parameter

dotnet YouApp.dll --urls http://localhost:3000

Kestrel-section in appsettings.json

"Kestrel": { 
	"EndPoints": { 
		"Http": { 
			"Url": "http://localhost:3000"
		} 
	} 
}

Environment variable (bash)

export ASPNETCORE_URLS=http://localhost:3000

Environment variable (bash, multiple urls)

export ASPNETCORE_URLS=http://localhost:3000\; https://localhost:3001

(Note: The semicolon has to be escaped with a backslash so it won’t be interpreted by the bash shell)

The list is by no means complete. At this moment I am mostly interested in configuration via environment variables for docker/DevOps/automation scenarios.