【问题标题】:ASP.NET Core 2.0 ngrok 502 Bad Gateway ErrorASP.NET Core 2.0 ngrok 502 错误网关错误
【发布时间】:2018-08-14 12:21:47
【问题描述】:

我一直在使用带有 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

【问题讨论】:

  • 是--host-header 不是-host-header,这可能是你的问题
  • 两者的工作原理相同。我认为问题不在于这个。在我使用的 asp.net 4.x 上一切正常。 – Deleroy 10 分钟前
  • 真的吗?当我只使用一个破折号时它对我不起作用

标签: c# asp.net visual-studio asp.net-core ngrok


【解决方案1】:

我解决了我的问题。

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 Core 使用不同的端口进行 SLL 连接,并且默认使用它。

在 ngrok 中将端口更改为正常(在我的情况下为 59890)解决了问题。

【讨论】:

    【解决方案2】:

    我想发布以下修复程序,如果有人使用 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 错误。

    【讨论】:

    • 对我来说,这个解决方案可以代替 Deleroy 的解决方案。
    • 请注意,此解决方案需要在 ngrok.com 上注册:Forwarding to local port 443 or a local https:// URL is only available after you sign up
    【解决方案3】:

    只需在项目->属性右键单击,然后禁用SSL

    【讨论】:

      【解决方案4】:

      通过转发到 http 端口,我能够让 ngrok 使用 http 和 https。例如,如果您的应用在 http 端口 5000 和 https 端口 5001 上运行,则运行:

      ngrok http 5000
      

      【讨论】:

        猜你喜欢
        • 2017-03-28
        • 2016-07-04
        • 2020-08-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-07-07
        相关资源
        最近更新 更多