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
The HTTP Error 502.5 - Bad Gateway and HTTP Error 502.5 - Process Failure error messages occur in ASP.NET Core when IIS fails to execute the dotnet process. I've seen this error happen for two different reasons:.NET Core Runtime is not installed web.config file has not been transformed
The 502 Bad Gateway error is an HTTP status code that means that one server on the internet received an invalid response from another server. 502 Bad Gateway errors are completely independent of your particular setup, meaning that you could see one in any browser, on any operating system, and on any device.
Now that ngrok is installed and authenticated, you can create a tunnel. First, you need to start your ASP.NET Core application and take note of the port that it is using, specifically the HTTPS port, which is 5001 in the sample below. Start an HTTP tunnel by running the command ngrok http and passing the port, for example:
Let’s look at how this works and how you can configure ngrok to work with an ASP.NET Core application. To install ngrok, head over to their download page and download the correct version of ngrok for your operating system. Once you have downloaded the ZIP file, you can extract it to a directory on your computer.
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.
Just go Right click on project->Properties and than Disable SSL.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With