![](/img/trans.png)
[英]502 Bad Gateway nginx and ASP.NET Core 3.1 when upload big file
[英]ASP.NET Core 2.0 ngrok 502 Bad Gateway Error
我一直在将 ngrok 与 ASP.NET 4.X 一起使用,没有遇到任何问题。
不幸的是,当我尝试在 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 没有帮助。
我解决了我的问题。
属性/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 Core 使用不同的端口进行 SLL 连接,并且默认情况下使用它。
在 ngrok 中将端口更改为正常(在我的情况下为 59890)解决了这个问题。
我想发布以下修复程序,如果有人使用 Docker 通过 https 运行 ASP Core 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 错误。
只需右键单击项目->属性,然后单击禁用SSL 。
通过转发到 http 端口,我能够让 ngrok 使用 http 和 https。 例如,如果您的应用程序在 http 端口 5000 和 https 端口 5001 上运行,请运行:
ngrok http 5000
这是 ngrok 的一个问题。 要使 ngrok 与 .Net Core 一起工作,您必须...
如果您使用 Java 编写 API,则要简单得多。 您所要做的就是输入 ngrok http 。
不知道为什么 ngrok 比 .Net 更喜欢 Java,但这就是我们生活的世界。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.