Ngrok 无法完成隧道连接

Ngrok Falied to complete Tunnel connection

我正在处理我的第一个 Django 项目。尝试通过 ngrok.I 运行 python manage.py 运行服务器连接到我的课程的自动评分器。我可以在 http://127.0.0.1/8000 看到该网站,它正在运行。我尝试了命令 ngrok http 80 并得到了转发 URL。当我尝试查看 Http://xxxxxxxngrok.io/127.0.0.1/8000 时,出现以下错误:

“与 http://444e-2600-1700-5egb-70c0-c843-879c-12ad-2b03.ngrok.io 的连接已成功连接到您的 ngrok 客户端,但客户端无法建立与本地地址 localhost:80 的连接。

确保 Web 服务在 localhost:80 上 运行 并且它是一个有效地址。

遇到的错误是:dial tcp [::1]:80: connectex: No connection could be because the target machine actively refused.

我在 运行 runserver 命令后输入了 netstat。它显示 127.0.0.1/8000 状态为“listening”

我该如何解决这个问题?

如果您在 http://127.0.0.1:8000 托管上游服务,那么用于启动 ngrok 的命令应该是:ngrok http 8000。 ngrok 提供给您的 link 应该按原样工作,因为您不必像您在问题中描述的那样在它的末尾附加任何内容。

如果还是不行,尝试重写主机 header 使用:ngrok http 8000 --host-header rewrite.

查看 ngrok 文档以获取更多信息:https://ngrok.com/docs

编辑:忘记提及如果您想直接向 Django 应用添加逻辑以控制代理,请查看此示例:https://pyngrok.readthedocs.io/en/latest/integrations.html#django