Ngrok与vagrant在Windows 10上无法使用。

3
我正在尝试通过ngrok公开我的本地服务器。我使用vagrant在本地服务器上运行我的项目,所以我了解到有一个适用于vagrant和ngrok的插件:"vagrant share"。我已经下载了ngrok,但当我运行命令vagrant share时,出现以下结果:
“Vagrant尝试运行的可执行文件'ngrok'未找到在PATH变量中。必须安装'ngrok'可执行文件才能运行Vagrant share。如果当前已在非标准位置安装'ngrok',请将该位置追加到PATH变量并再次运行此命令。”
我已经将ngrok放入环境变量中,但它仍然无法工作。
有什么办法可以解决这个问题吗?我已经困扰了好几天,还是没有解决。
3个回答

0

您必须明确将ngrok添加到Windows PATH中。我怀疑vagrant share插件没有安装ngrok

为了做到这一点,我恰好在使用Visual Studio Code时,使用PowerShell作为终端。我从ngrok网站以zip形式下载了ngrok,解压缩后,将其放置在我的Windows主目录中,并将其添加到PowerShell路径中。然后vagrant share立即工作(我不需要显式设置authtoken或连接帐户)。请将下面的windowsuser替换为您的帐户ID。

  1. 从此处下载ngrok-stable-windows-amd64.zip:https://ngrok.com/download
  2. 在您的下载文件夹中双击它,将其复制并粘贴到可访问的文件夹中,例如c:\Users\windowsuser
  3. 在Powershell终端中执行:$env:Path += ";c:\users\windowsuser"
  4. 在Powershell终端中验证ngrok.exe现在是否可用,如下所示:
PS C:\Users\windowsuser\vagrant_getting_started> ngrok
NAME:
   ngrok - tunnel local ports to public URLs and inspect traffic

DESCRIPTION:
    ngrok exposes local networked services behinds NATs and firewalls to the
    public internet over a secure tunnel. Share local websites, build/test
    webhook consumers and self-host personal services.
    Detailed help for each command is available with 'ngrok help <command>'.
    Open http://localhost:4040 for ngrok's web interface to inspect traffic.

EXAMPLES:
    ngrok http 80                    # secure public URL for port 80 web server
    ngrok http -subdomain=baz 8080   # port 8080 available at baz.ngrok.io
    ngrok http foo.dev:80            # tunnel to host:port instead of localhost
    ngrok http https://localhost     # expose a local https server
    ngrok tcp 22                     # tunnel arbitrary TCP traffic to port 22
    ngrok tls -hostname=foo.com 443  # TLS traffic for foo.com to port 443
    ngrok start foo bar baz          # start tunnels from the configuration file

VERSION:
   2.3.35

AUTHOR:
  inconshreveable - <alan@ngrok.com>

COMMANDS:
   authtoken    save authtoken to configuration file
   credits      prints author and licensing information
   http         start an HTTP tunnel
   start        start tunnels by name from the configuration file
   tcp          start a TCP tunnel
   tls          start a TLS tunnel
   update       update ngrok to the latest version
   version      print the version string
   help         Shows a list of commands or help for one command
PS C:\Users\windowsuser\vagrant_getting_started> 
  1. 然后运行vagrant share命令,就像你看到的一样,我正在学习vagrant教程。
PS C:\Users\windowsuser\vagrant_getting_started> vagrant share
==> default: Detecting network information for machine...
    default: Local machine address: 127.0.0.1
    default:
    default: Note: With the local address (127.0.0.1), Vagrant Share can only
    default: share any ports you have forwarded. Assign an IP or address to your
    default: machine to expose all TCP ports. Consult the documentation
    default: for your provider ('virtualbox') for more information.
    default:
    default: Local HTTP port: 4567
    default: Local HTTPS port: disabled
    default: Port: 2200
    default: Port: 4567
==> default: Creating Vagrant Share session...
==> default: HTTP URL: http://e058e1d1b464.ngrok.io
==> default:

如果您使用的是普通的CMD提示符,您可以像下面这样设置PATH,然后上述相同的ngrok和vagrant命令也将起作用。
C:\Users\windowsuser>set PATH=%PATH%;C:\Users\windowsuser

0
在您的$PATH中,只提供ngrok二进制可执行文件所在的路径。例如:/path/to是正确的,而不是/path/to/ngrok

至少这是我一开始犯的错误。希望这个细节能对某人有所帮助。原则上@learning2learn的答案是正确的。


0

你尝试过手动安装 vagrant share 插件吗?

vagrant plugin install vagrant-share

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