Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

webdevb's avatar

Homestead & Ngrok

Hey guys,

I'm trying to setup Ngrok on my homestead but don't seem to be doing it successfully, everytime i run ngrok http laravel.app:8000 and browse to the URL given my Ngrok I just get an error 'Tunnel not correctly routed'.

I have multiple sites setup on my homestead so I'm not sure if I have to configure something differently.

Any help would be great.

Thanks,

Scott

0 likes
13 replies
renedekat's avatar

You need to make sure Homestead (nginx) listen on that ngrok domain.

Go to your Homestead vm and as root (or sudo), copy the vhost file in /etc/nginx/sites-available and name it mydomain.ngrok.io (or add an alias to the existing vhost)

Go to /etc/nginx/sites-enabled and symlink the new vhost file using ln -s

Reload nginx.

knox's avatar
knox
Best Answer
Level 4

I find it easiest to run ngrok outside homestead and just pointed at the homestead IP, and with a host-header for whichever homestead project I'm working with so for example;

ngrok 192.168.10.10:80 -host-header=myapp.dev

13 likes
webdevb's avatar

Hey Knox,

Thanks for this, managed to get it working a 'slightly' different way.

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

5 likes
elasticsteve's avatar

ngrok 192.168.10.10:80 -host-header=myapp.dev

didn't work. ERROR: Unrecognized command: 192.168.10.10:80

but "ngrok http -host-header=rewrite site.dev:80" worked perfectly!

thanks

3 likes
svpernova09's avatar

As of Homestead 5.x you can use the share homestead.app command to fire off ngrok to listen for homestead.app

10 likes
dyudko44's avatar

@elasticsteve

I think this is the correct command (was missing the "http")

ngrok http 192.168.10.10:80 -host-header=site.dev

3 likes
yulquen's avatar

Maybe i'm missing something, but when i share a site in homestead, it works fine but just for the very first page. All other links in the site still points to the local url configured in the Homestead.yaml file. For example the Login or Register Forms in Laravel Auth. It still works on my machine though, but for other people that want to access the whole site, it doesn't work of course.

Do i need to configure a specific nginx vhost for a ngrok domain and start ngrok with that -host-header option?

2 likes
zecipriano's avatar

I was having the same issue as rephluX. I got it to work by setting a new site in Homestead.yaml with a corresponding ngrok domain (pointing to the same folder).

In Homestead.yaml:

- map: yoursite.dev
  to: /home/vagrant/code/yoursite/public
- map: yoursite.ngrok.io
  to: /home/vagrant/code/yoursite/public

Then start ngrok like this:

ngrok http --subdomain=yoursite --host-header=yoursite.ngrok.io yoursite.dev:80

Notes:

You need a ngrok account to set a subdomain.

The ngrok pricing page says that you need a paid plan to use custom subdomains. I'm able to set a subdomain with the free plan, so not sure what is the situation here.

If you can't set a subdomain, I guess you have to start the ngrok tunnel first and then provision a site with the given url (having to do this every time you start ngrok).

2 likes
osster's avatar

rephluX, I'm not sure about safety, but you can add few lines to RouteServiceProvider.php

    public function boot()
    {
        // ngrok.io Hack
        $scheme = "";
        $host = "";
        $baseInfo = parse_url(config("app.url"));
        $baseHost = $baseInfo["host"];
        $baseScheme = $baseInfo["scheme"];

        if (isset($_SERVER["HTTP_X_ORIGINAL_HOST"])) {
            $scheme = isset($_SERVER["HTTP_X_FORWARDED_PROTO"]) ? $_SERVER["HTTP_X_FORWARDED_PROTO"] : $baseScheme;
            $host = isset($_SERVER["HTTP_X_ORIGINAL_HOST"]) ? $_SERVER["HTTP_X_ORIGINAL_HOST"] : "";
        } elseif (isset($_SERVER["HTTP_REFERER"])) {
            $info = parse_url($_SERVER["HTTP_REFERER"]);
            $host = $info["host"];
            $scheme = $info["scheme"];
        }

        if ($host != "" && $host != $baseHost && preg_match("#ngrok\.io#", $host)) {
            $scheme ?: $baseScheme;
            \URL::forceRootUrl("{$scheme}://{$host}");
        }
        // End ngrok.io Hack

        parent::boot();
    }

That's it.

3 likes
josiahmann's avatar

This was super helpful.

For some reason I couldn't get past the login with the homestead "share" command (kept getting a 409 and it was redirecting me to the original domain).

Please or to participate in this conversation.