Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tunnel a localhost subdirectory through ngrok?

Tags:

Objective: want to share a website preview using ngrok, which creates a tunnel from which my localhost can be seen with an url of something like mywebsite.ngrok.io

Problem: I use WAMP and my localhost folder looks something like this:

localhostdirectory    |-- website1    |-- website2    |-- etc 

To access a website I type to localhost/website1/ in the browser, I would like to tunnel only that URL, the possible solutions would be:

  1. Setting up a Virtual host, I would go through the hassle of manually setting up a virtual host, then I get something like website1.dev, and then I would pass it to ngrok as the host header in the HTTP request, like that:

    ngrok http -host-header=website1.dev 80 

    I didn't understand what the host header is though, and why can't I pass a relative url like localhost/website1/, also what is the rewrite option?

  2. Change the folder directory of my localhost to the folder of the website, I would prefer not to do that.

Is there a better way to accomplish my objective in an easier way, maybe going through WAMP aliases?

like image 333
Pontiacks Avatar asked May 03 '15 17:05

Pontiacks


People also ask

How does Ngrok tunneling work?

ngrok Secure Tunnels work by using a locally installed ngrok agent to establish a connection to the ngrok service. Once the connection is established, you get a public endpoint that you or others can use to access your local service.


2 Answers

If you make do with Apache Vhost you just have to exec command

ngrok http -host-header=rewrite YOUR-LOCAL-DOMAIN:PORT

Dont forgot to edit host file for resolution @IP <-> YOUR-LOCAL-DOMAIN

like image 163
Abdourahmane FALL Avatar answered Sep 17 '22 12:09

Abdourahmane FALL


I tried below way.

When I ran $ ./ngrok http 80 ngrok listen to localhost:80 which shows dashboard because apache server is running on port 80. Then I tried running subfolder in another port, which solved problem. Assume you have project in xyz and want ngrok should points it. Then do following

$ cd /opt/lampp/htdocs/xyz $ php -S localhost:8080 

Here 8080 is any unused port. localhost:8080 direct points to xyz and then open other terminal

$ ./ngrok http 8080

By doing this ngrok will listen to 8080 port were your xyz is running.

Hope this helps!!

like image 42
Rohan Khude Avatar answered Sep 19 '22 12:09

Rohan Khude