33

I'm trying to tunnel a clients site in my sites directory with "ngrok http -host-header = client1.dev 80", I get a 404 when accessing the url. After some experimenting, if I put an index.html file in the home directory, it will display that file. Not sure why a file in the home directory works while files in sites directory do not. I must be missing something here..Any ideas?

directory structure :

www
  |home
  |sites
    | client1
    | client2
      ... 

vhost.conf :

<Directory "/www">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>

<Virtualhost *:80>
VirtualDocumentRoot "/Users/myname/www/home/wwwroot"
ServerName home.dev
UseCanonicalName Off
</Virtualhost>

<Virtualhost *:80>
VirtualDocumentRoot "/Users/myname/www/sites/%1/wwwroot"
ServerName sites.dev
ServerAlias *.dev
UseCanonicalName Off
</Virtualhost>
paul degrand
  • 345
  • 1
  • 3
  • 7

4 Answers4

95

Cool All your config is good, You just have to exec command

ngrok http -host-header=rewrite home.dev:80

ngrok http -host-header=rewrite sites.dev:80

New Command (8-30-22 edit):

ngrok http --host-header=rewrite sites.dev:80
Michael S.
  • 3,050
  • 4
  • 19
  • 34
Abdourahmane FALL
  • 1,836
  • 13
  • 7
  • what you do ? do you config your host file ? In first you have to config your virtual host from apache server than you config your host file to resole [YOUR_SITE_NAME : hove.dev] at 127.0.0.1 – Abdourahmane FALL Dec 10 '15 at 06:08
43

For me it only worked with:

ngrok http -host-header=sites.dev 80

Change sites.dev to you virtual host name

Source: Virtual hosts (MAMP, WAMP, etc)

Sand Of Vega
  • 2,297
  • 16
  • 29
Diogo Gomes
  • 2,135
  • 16
  • 13
  • Thanks! When I have a chance I will try this out and get back to you. I left it alone for a while bc it wasn't working obv. the way I wanted it to. – paul degrand Mar 28 '17 at 15:49
  • 1
    This worked for me, I have seen the other way that @AbdourahmaneFALL mentioned but I think this is if you are running ngrok from the host machine – doz87 Jun 27 '17 at 05:42
  • 1
    I believe this is the way to go for Ngrok2, their latest version. @AbdourahmaneFALL would work for the older version of Ngrok I guess. – Akshay Agarwal Nov 27 '17 at 22:30
6

If you want a more permanent configuration, you can edit your ~/.ngrok2/ngrok.yml config file.

tunnels:
  test: # the name of your tunnel to call from the command line
    addr: 80 # Your localhost port
    proto: http
    host_header: test.localhost # Your localhost virtualhost

And then you can run from your command line

ngrok start test
Alex McCabe
  • 1,852
  • 2
  • 20
  • 33
  • 1
    Just a comment to say, if you need to use the syntax in @Abdourahmane FALL's answer, in `host_header` set the value to `rewrite`, then in `addr` set this to your vhost, including the port (for example `my.vhost.com:80`) – BrynJ Mar 25 '19 at 10:50
2

Not sure if the command got changed from the previous versions.

From the help doc of Ngrok,

ngrok http --host-header=ex.com 80          # rewrite the Host header to 'ex.com'

Notice the double hyphens(--).

Harish ST
  • 1,475
  • 9
  • 23