apachevagrantlocaltunnel

Vagrant LocalTunnel and ServerAlias not working


I have a local Vagrant VM on which I develop apps. I'm tired of using Vagrant Share to provide public urls because it keeps disconnecting, so I installed localtunnel.me

The issue I'm having though is that my Apache headers are showing the local configuration, which is a problem. When I access my app via a localtunnel.me url, I need things like $_SERVER['HTTP_HOST'] to read "myproject.localtunnel.me" and not "myproject.local".

I have added my public localtunnel.me domain to my ServerAlias config for Apache and reloaded Apache. When I initiate lt with:

lt -p 80 -s myproject -l myproject.localtunnel.me 

I then get a 504 Gateway Timeout when navigating to myproject.localtunnel.me

If I do:

lt -p 80 -s myproject -l myproject.local 

When I go to http://myproject.localtunnel.me phpinfo() shows me that $_SERVER['HTTP_HOST'] == "myproject.local".

This breaks many of my connections with other webhooks and API services because the headers don't match the URL.

Any ideas on how to overcome this (besides ngrok which seems to be more resource intensive to run).


Solution

  • It turns out that LocalTunnel works a little differently to Vagrant Share.

    In order to make this work:

    lt -p 80 -s myproject -l myproject.localtunnel.me 
    

    You need need to add myproject.localtunnel.me to the ServerAlias line in the site's conf file (which I had).

    But you ALSO need to add it to your Vagrant's host file:

    127.0.1.1 myproject.localtunnel.me
    

    Not having the hosts entry caused the 504 error.

    Hope this helps someone else out there.