Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NGrok and Laravel

Tags:

laravel

ngrok

I want to deploy my local larvel website online with NGROK. I'm using Laragon with Apache server, I use this command :

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

It almost work, but the asset file (like CSS/Image) are still link to my local server (site.dev). And it's the same for my link, the laravel routing command : {{ route('ngo') }} return site.dev/ngo instead of my online tunnel (http://number.ngrok.io/ngo)

I've try to :

Edit the http.conf (https://forum.laragon.org/topic/88/allow-outside-other-devices-phones-tablets-to-access-your-local-server-using-ngrok)

Change my Laravel App url in config/app.php

Change my url in .env file

Nothings work

like image 627
Kaherdin Avatar asked Apr 19 '17 08:04

Kaherdin


People also ask

What Ngrok used for?

Ngrok is a cross-platform application that exposes local server ports to the Internet. Their website claims, “[so you can] spend more time programming—one command for an instant, secure URL to your localhost server through any NAT or firewall.”

What is Ngrok in Linux?

Ngrok is a cross-platform tool that uses cloud services to expose local networked services behind NATs and firewalls over a secure tunnel. Ngrok can also share local websites, build/test webhook consumers, and self-host personal services.

How use Ngrok Linux?

Start command reference start starts the tunnel by name from the config file. The Ngrok start command Runs tunnels by name from a config file. You can specify any number of tunnel names. You can start all tunnels from the configuration file by specifying the –all switch.


1 Answers

I ran into this problem myself just now, but also found a way to fix it:

Run the ngrok command without the -host-header=rewrite part, resulting in

ngrok http site.dev:80

After this, edit your http.conf file and add the ngrok domain as a server alias. For example:

ServerAlias nd3428do.ngrok.io

The problem is that Laravel's route helper uses the HOST header, which is rewritten to site.dev. Without the -host-header part, the header isn't rewritten and now it works.

like image 120
greew Avatar answered Oct 13 '22 05:10

greew