ASP.NET Core 2.0 ngrok 502 网关错误
ASP.NET Core 2.0 ngrok 502 Bad Gateway Error
我一直在 ASP.NET 4.X 中使用 ngrok,没有遇到任何问题。
不幸的是,当我尝试转发 ASP.NET Core 2 中的应用构建时,我 运行 遇到了一个我无法解决的问题。
我尝试了以下命令组合来启动 ngrok:
ngrok http 44374-host-header="localhost:44374"
ngrok http -host-header=rewrite localhost:44374
ngrok http 44374
全部给出相同的结果。 Ngrok 隧道启动,但是当我尝试打开给定的转发 url 时,站点正在加载几分钟,然后显示 502 Bad Gateway 错误。它适用于http和https版本。
运行 Visual Studio 或 ngrok 作为管理员没有帮助。
Website works correctly with localhost
Running website with ngrok gives 502 Bad Gateway error
我解决了我的问题。
properties/launchSettings.json内容:
{
"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/"
}
}
}
所以,事实证明 ASP.NET 核心使用不同的端口进行 SLL 连接,并且默认使用它。
在 ngrok 中将端口更改为正常(在我的例子中是 59890)解决了问题。
只需在项目上右键单击->属性然后禁用SSL。
我想发布以下修复程序,如果有人使用 Docker 在 https 上 运行 宁 ASP 核心 2.X 应用程序可能会有所帮助,以下适用于我:
ngrok http https://localhost:[PORT] --host-header="localhost:[PORT]" --subdomain [YOUR_SUBDOMAIN]
Example:
ngrok http https://localhost:44390 --host-header="localhost:44390" --subdomain 2gtest
这样我就可以 运行 ngrok 而不会出现 502 错误。
通过转发到 http 端口,我能够让 ngrok 使用 http 和 https。因此,例如,如果您的应用 运行s 在端口 5000 上用于 http,在端口 5001 上用于 https,运行:
ngrok http 5000
我一直在 ASP.NET 4.X 中使用 ngrok,没有遇到任何问题。
不幸的是,当我尝试转发 ASP.NET Core 2 中的应用构建时,我 运行 遇到了一个我无法解决的问题。
我尝试了以下命令组合来启动 ngrok:
ngrok http 44374-host-header="localhost:44374"
ngrok http -host-header=rewrite localhost:44374
ngrok http 44374
全部给出相同的结果。 Ngrok 隧道启动,但是当我尝试打开给定的转发 url 时,站点正在加载几分钟,然后显示 502 Bad Gateway 错误。它适用于http和https版本。
运行 Visual Studio 或 ngrok 作为管理员没有帮助。
Website works correctly with localhost
Running website with ngrok gives 502 Bad Gateway error
我解决了我的问题。
properties/launchSettings.json内容:
{
"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/"
}
}
}
所以,事实证明 ASP.NET 核心使用不同的端口进行 SLL 连接,并且默认使用它。
在 ngrok 中将端口更改为正常(在我的例子中是 59890)解决了问题。
只需在项目上右键单击->属性然后禁用SSL。
我想发布以下修复程序,如果有人使用 Docker 在 https 上 运行 宁 ASP 核心 2.X 应用程序可能会有所帮助,以下适用于我:
ngrok http https://localhost:[PORT] --host-header="localhost:[PORT]" --subdomain [YOUR_SUBDOMAIN]
Example:
ngrok http https://localhost:44390 --host-header="localhost:44390" --subdomain 2gtest
这样我就可以 运行 ngrok 而不会出现 502 错误。
通过转发到 http 端口,我能够让 ngrok 使用 http 和 https。因此,例如,如果您的应用 运行s 在端口 5000 上用于 http,在端口 5001 上用于 https,运行:
ngrok http 5000