ASP.NET Core 2.0 ngrok 502 Bad Gateway Error

I want to publish the following fix that may help if somebody is running an ASP Core 2.X app over https with Docker, the following worked for me:

ngrok http https://localhost:[PORT] --host-header="localhost:[PORT]" --subdomain [YOUR_SUBDOMAIN]

Example:
ngrok http https://localhost:44390 --host-header="localhost:44390" --subdomain 2gtest

With that I was able to run ngrok without getting 502 errors.


I solved my problem.

properties/launchSettings.json content:

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:59889/",
      "sslPort": 44374
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "https://localhost:44374/",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "NgrokTEST": {
      "commandName": "Project",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "http://localhost:59890/"
    }
  }
}

So, it turns out that ASP.NET Core uses different port for SLL connection and it's used by default.

Changing port to normal (59890 in my case) in ngrok solved the problem.