简体   繁体   English

带有 vagrant 的 Ngrok 在 Windows 10 中不起作用

[英]Ngrok with vagrant doesn't work in windows 10

I'm trying to expose my local server through ngrok.我正在尝试通过 ngrok 公开我的本地服务器。 I'm using vagrant to run my project in my localserver so, I read that there is a plugin for vagrant and ngrok, "vagrant share".我正在使用 vagrant 在我的本地服务器上运行我的项目,所以,我读到有一个 vagrant 和 ngrok 插件,“vagrant share”。 I already downloaded ngrok but when I run the command vagrant share, this is the result :我已经下载了 ngrok,但是当我运行命令 vagrant share 时,结果如下:

The executable 'ngrok' Vagrant is trying to run was not found in the PATH variable.在 PATH 变量中找不到试图运行的可执行文件 'ngrok' Vagrant。 The 'ngrok' executable is required to run Vagrant share.运行 Vagrant 共享需要“ngrok”可执行文件。 If 'ngrok' is currently installed in a non-standard location, append that location to the PATH variable and run this command again.如果“ngrok”当前安装在非标准位置,请将该位置附加到 PATH 变量并再次运行此命令。

I already put ngrok in the environment variable but it doesn't work.我已经将 ngrok 放在环境变量中,但它不起作用。

Any idea how to fix it?知道如何修复它吗? I have several days with this problem and I can't solve it.我有好几天遇到这个问题,但无法解决。

您是否尝试过手动安装vagrant share插件?

vagrant plugin install vagrant-share

You have to explicitly have ngrok in your Windows PATH.您必须在 Windows PATH 中明确包含 ngrok。 I suspect the vagrant share plugin does not install ngrok .我怀疑vagrant share插件没有安装ngrok

To do this same thing for myself, I happened to be running with Visual Studio Code, using PowerShell as the Terminal.为了为自己做同样的事情,我碰巧在运行 Visual Studio Code,使用 PowerShell 作为终端。 I downloaded ngrok in zip form from the ngrok web site, extracted, placed it in my Windows home directory, and added that to the PowerShell path.我从 ngrok 网站下载了 zip 格式的 ngrok,将其解压缩,放在我的 Windows 主目录中,然后将其添加到 PowerShell 路径中。 Then vagrant share immediately worked (I did not have to explicitly setup an authtoken or connect an account).然后vagrant share立即起作用(我不必明确设置 authtoken 或连接帐户)。 Below substitute windowsuser with your account id.下面用您的帐户 ID 替换windowsuser

  1. Download ngrok-stable-windows-amd64.zip from here: https://ngrok.com/download从这里下载ngrok-stable-windows-amd64.zip: https://ngrok.com/download
  2. Doubleclick on it in your Downloads folder, copy and paste it into an accessible folder, like c:\\Users\\windowsuser在“下载”文件夹中双击它,将其复制并粘贴到可访问的文件夹中,例如c:\\Users\\windowsuser
  3. In Powershell terminal, execute: $env:Path += ";c:\\users\\windowsuser"在 Powershell 终端中,执行: $env:Path += ";c:\\users\\windowsuser"
  4. In Powershell terminal, verify ngrok.exe is now available, like so:在 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. Then vagrant share should work;那么vagrant share应该可以工作; as you can see, I am working through the vagrant tutorials.如您所见,我正在学习 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:
  1. If you are using a regular CMD prompt instead, you can set the PATH like the following, and the exact same ngrok and vagrant commands as above will also work.如果您使用的是常规 CMD 提示符,则可以像下面这样设置 PATH,并且与上面完全相同的 ngrok 和 vagrant 命令也可以使用。
C:\Users\windowsuser>set PATH=%PATH%;C:\Users\windowsuser

In your $PATH provide only the path to where ngrok binary executable can be found.在您的 $PATH 中仅提供可以找到 ngrok 二进制可执行文件的路径。 For example: /path/to is correct , and not /path/to/ngrok例如: /path/to是正确的,而不是/path/to/ngrok

At least that was my mistake at first.至少那是我一开始的错误。 Hope that detail helps to someone.希望这个细节对某人有帮助。 In principle @learning2learn 's answer is correct.原则上@learning2learn 的答案是正确的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM