Https configuration issues with Kestrel in aspnetcore 2.0 #1851
Description
I faced the issue https://github.com/dotnet/cli/issues/6516 and was advised to move to the docker image aspnetcore 2 rather than the dotnet.
dotnet --info
NET Command Line Tools (2.0.0-preview1-005977)
Product Information:
Version: 2.0.0-preview1-005977
Commit SHA-1 hash: 414cab8a0b
Runtime Environment:
OS Name: Mac OS X
OS Version: 10.12
OS Platform: Darwin
RID: osx.10.12-x64
Base Path: /usr/local/share/dotnet/sdk/2.0.0-preview1-005977/
Microsoft .NET Core Shared Framework Host
Version : 2.0.0-preview1-002111-00
Build : 1ff021936263d492539399688f46fd3827169983
startup.cs
WebHost.CreateDefaultBuilder(args).UseStartup<Startup>().Build().Run();
When I run my app locally, I set the ASPNETCORE_ENV to http://localhost:5000 using vscode tasks.
When I deploy (to Google App Engine) via Dockerfile, i set the following (notice http vs https):
EXPOSE 8080/tcp
ENV ASPNETCORE_URLS https://*:8080
This was good because I could control the port and http/https using environment variable only.
Now Kestrel returns:
System.InvalidOperationException: HTTPS endpoints can only be configured using KestrelServerOptions.Listen().
It seems I have to hardcode this value in Program.cs
which I can't really do (flexibility is lost).
I deploy several services in docker containers that are ALL listening on port 8080 (Google App Engine requirement). App Engine provides the https certificate automatically so i do now own it (its probably just a reverse proxy by the way but it redirect to https).
But when I run them locally, I override the env var and specify some custom port 5000, 5001 so I can run them all at the same time...
How would you recommend I now handle this case using the aspnetcore 2.0 image?
The Kestrel ListenOptionsHttpsExtensions seem to require a certificate or a password which I do not have as it is managed by Google...
PS: If i use this code
.UseKestrel(options =>
{
options.Listen(IPAddress.Any, 8080);
}
and overrides using an environment variable on top, it won't:
Microsoft.AspNetCore.Server.Kestrel:Warning: Overriding address(es) http://*:5001. Binding to endpoints defined in UseKestrel() instead.
Overriding address(es) http://*:5001. Binding to endpoints defined in UseKestrel() instead.