One of the nice things of Laravel Valet is that it includes an easy way to make your local site available publicly. For this it has the aforementioned Ngrok built-in. To use it, just run the valet share
command, and your local site will be shared through a *.ngrok.io
subdomain.
However, when combining valet share
with valet secure
(which serves your local site over HTTPS) it won’t work: you’ll end up in a 301 Redirect Loop when visiting your site through the *.ngrok.io
domain.
To fix this issue there are two options:
-
The old way: Manually edit your sites Nginx config file and remove the block that listens on port 80.
As valet issue#382 details, you can fix this error by manually editing the Nginx configuration for your site.
Say your site is
mysite.test
, then its Nginx config file can be found at~/.config/valet/Nginx/mysite.test
.💁♂️ Can’t find the file at said location?
Note that Valet versions < 2.1.0 use the
~/.valet
folder instead of the~/.config/valet/
folderInside the
~/.config/valet/Nginx/mysite.test
file, look for a block that looks like this:server { listen 80; server_name mysite.test; return 301 https://$host$request_uri; }
Now remove that block entirely (or comment it out using the
#
sign), save it, and restart valet usingvalet restart
.When now using
valet share
it will work fine 🙂 -
The new way: Upgrade Valet to version 2.1.3 or newer
It came to my attention through valet issue#148 that valet 2.1.3 got released just three days ago and that it contains an out-of-the-box fix for this bug … yay! 🎉
To upgrade your Valet install run this:
# update package composer global update # Make Valet do its housekeeping valet install
When now using
valet share
it will work fine 🙂Note that when coming from Valet < 2.1.0 the
~/.valet
folder will have moved to~/.config/valet/
There ya go 🙂
Thank me with a coffee.
I don\'t do this for profit but a small one-time donation would surely put a smile on my face. Thanks!
To stay in the loop you can follow @bramus or follow @bramusblog on Twitter.