ASP.NET Core 2.0 ngrok 502 Bad Gateway Error

Deleroy picture Deleroy · Mar 6, 2018 · Viewed 7.5k times · Source

I have been using ngrok with ASP.NET 4.X without encountering any problems.

Unfortunately, when I try to forward app build in ASP.NET Core 2 I run into a problem that I can't solve.

I tried following combinations of commands to start ngrok:

ngrok http 44374-host-header="localhost:44374"

ngrok http -host-header=rewrite localhost:44374

ngrok http 44374

All give the same result. Ngrok tunnel starts, but when I try to open given forwarding url, site is loading few minutes and then 502 Bad Gateway error is shown. It applies to both http and https version.

Running Visual Studio or ngrok as administrator does not help.

Website works correctly with localhost

Running website with ngrok gives 502 Bad Gateway error

Answer

Deleroy picture Deleroy · Mar 7, 2018

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.