简体   繁体   中英

Ngrok with vagrant doesn't work in windows 10

I'm trying to expose my local server through 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". I already downloaded ngrok but when I run the command vagrant share, this is the result :

The executable 'ngrok' Vagrant is trying to run was not found in the PATH variable. The 'ngrok' executable is required to run Vagrant share. If 'ngrok' is currently installed in a non-standard location, append that location to the PATH variable and run this command again.

I already put ngrok in the environment variable but it doesn't work.

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. I suspect the vagrant share plugin does not install ngrok .

To do this same thing for myself, I happened to be running with Visual Studio Code, using PowerShell as the Terminal. 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. Then vagrant share immediately worked (I did not have to explicitly setup an authtoken or connect an account). Below substitute windowsuser with your account id.

  1. Download ngrok-stable-windows-amd64.zip from here: https://ngrok.com/download
  2. Doubleclick on it in your Downloads folder, copy and paste it into an accessible folder, like c:\\Users\\windowsuser
  3. In Powershell terminal, execute: $env:Path += ";c:\\users\\windowsuser"
  4. In Powershell terminal, verify ngrok.exe is now available, like so:
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; as you can see, I am working through the vagrant tutorials.
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.
C:\Users\windowsuser>set PATH=%PATH%;C:\Users\windowsuser

In your $PATH provide only the path to where ngrok binary executable can be found. For example: /path/to is correct , and not /path/to/ngrok

At least that was my mistake at first. Hope that detail helps to someone. In principle @learning2learn 's answer is correct.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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