ngrok和ASP.NET Core应用程序的HTTPS隧道

17

ASP.NET CORE应用程序在Visual Studio中启动时,地址为https://localhost:44313/。 要测试性能,需要创建一个隧道。我使用ngrok和以下命令:

ngrok http -host-header=localhost 44313

但这对于https无效。

有人可以分享一个可用的示例吗?

6个回答

47
  1. 下载当前版本的ngrok
  2. 注册并获取令牌: https://dashboard.ngrok.com/auth
  3. 运行ngrok,并用以下命令设置令牌: ngrok authtoken YOUR_AUTHTOKEN
  4. 创建一个隧道: ngrok http --host-header=localhost https://localhost:44313

更新于2019年4月11日


1
我仍然无法在https上执行操作,您是否进行了其他更改? - thalacker
@thalacker 所有的都按照上面所述。但我使用最新的当前版本。 - al.koval
@thalacker 忘记澄清了,请确保使用在授权期间获得的令牌(https://dashboard.ngrok.com/auth)。 - al.koval
1
-host-header 应该是 --host-header - Mertus

13

使用ngrok版本2.3.29并添加了authtoken(不确定authtoken是否会影响结果,我只是按照在线安装指南添加了它)。

这个命令对我有效:

ngrok http https://localhost:{your-app-port} -host-header=localhost:{your-app-port}

与现有答案的区别:我将localhost:port传递给-host-header

与您的问题的区别:我使用ngrok http https://localhos:port代替ngrok http http://localhos:port(https而不是http)


1
使用版本3时,您必须使用--host-header。 - Elham Kohestani
1
这对我有帮助,谢谢!虽然我不太明白为什么。之前我是将其转发到http端点。 - Jim

4

现在您需要在主机标头之前放置两个横线

ngrok http https://localhost:{your-app-port} --host-header=localhost:"your-app-port"

4

更新至2023年3月。

在尝试以上所有选项均失败后,我从他们的文档中找到了以下内容:https://ngrok.com/docs/secure-tunnels/tunnels/http-tunnels/#host-header

要进行http隧道

e.g

ngrok http --host-header=rewrite http://localhost:44345

如果使用https, 例如

ngrok http --host-header=rewrite --scheme=https https://localhost:44345


0

0

如果您需要在免费计划上运行多个隧道,可以修改配置如下:

version: "2"
authtoken: 2OS8VCciyOWXR7XM33rh6RY79jT_7u8VsgzzfwoewzGnfG3lV
tunnels:
  first:
    addr: 5173
    proto: http    
  second:
    proto: http
    addr: https://localhost:7125
    host_header: rewrite
    schemes: [https]

然后运行

ngrok start --all

查找配置运行

ngrok config check

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接