37

I use mamp and I have virtual hosts all on port 8888. For example:

  • site1.dev:8888
  • site2.dev:8888

would point to localhost/site1/, localhost/site2/ etc.

Before using virtual hosts, I would just change my docroot to whatever project I was currently working on and would start ngrok like so

./ngrok http 8888 and it would launch and give me a random generated *.ngrok.io url.

My question is how do I specify the domain now since I am using virtual hosts?

I've tried ./ngrok http site1.dev:8888 and it starts but just serves up mamps webroot.

I am using a free account.

Ronnie
  • 11,138
  • 21
  • 78
  • 140

3 Answers3

91

If you prefer a free option, it is possible via:

ngrok http --host-header=site1.dev 80
Toph
  • 2,561
  • 2
  • 24
  • 28
demanzonderjas
  • 1,028
  • 8
  • 7
  • 46
    The answer above is correct for the question asked. But if you are using something like Vagrant (e.g. Homestead) and you have a private IP assigned to the virtual machine, the above will not work. You will need to use `$ ngrok http -host-header=rewrite site1.dev:80` – Cristian Calara Jun 14 '18 at 05:21
  • I have .test domains with subdomains like 'subdomain.site.test:80'. Then, this way works for me: `$ ngrok http 80 --host-header=subdomain.site.test:80` – pedrozopayares Aug 16 '22 at 19:46
  • 1
    Little observation, as of today, the param is `--host-header=[your_domain]`. The answer is just missing the extra dash at the beginning. – mrbitzilla Oct 21 '22 at 01:10
5

You can use custom domains with this syntax:

ngrok http --hostname=dev.example.com 8000

For reference: https://ngrok.com/docs#custom-domains

But a paid plan is needed.

giraffesyo
  • 4,860
  • 1
  • 29
  • 39
Pamput
  • 2,634
  • 2
  • 16
  • 16
4

Works just for paid plan, otherwise not works :(

The correct way to use a custom subdomain name is follow:

ngrok http -subdomain=mycustomsubdomain 80

Will generate:

Forwarding                    http://mycustomsubdomain.ngrok.io -> 127.0.0.1:80
Forwarding                    https://mycustomsubdomain.ngrok.io -> 127.0.0.1:80

More in docs: https://ngrok.com/docs#http-subdomain

Jonatas Eduardo
  • 834
  • 9
  • 18