Closed Sogl closed 5 years ago
Lines from SO helped me with host ngrok (not in Docker):
public function boot(\Illuminate\Http\Request $request)
{
if ($request->server->has('HTTP_X_ORIGINAL_HOST')) {
$request->server->set('HTTP_X_FORWARDED_HOST', $request->server->get('HTTP_X_ORIGINAL_HOST'));
$request->headers->set('X_FORWARDED_HOST', $request->server->get('HTTP_X_ORIGINAL_HOST'));
}
}
Any ideas how I can use your library in Docker without this change?
@Sogl by default this package build the ngrok command extracting the host and port from the app.url
configuration.
Probably this configuration in your app is currently localhost
.
Try to set the app.url
to https://myproject.dev
or pass the host in the artisan command:
php artisan ngrok myproject.dev
The same error with this line:
php artisan ngrok myproject.dev
On host machine I use Dnsmasq, that's how I installed it (see Dnsmasq
section):
https://getgrav.org/blog/macos-mojave-apache-mysql-vhost-apc
My nginx conf:
server {
listen 80;
listen [::]:80;
server_name myproject.dev;
root /var/www/myproject/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_pass php-upstream;
fastcgi_index index.php;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fixes timeouts
fastcgi_read_timeout 600;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
location /.well-known/acme-challenge/ {
root /var/www/letsencrypt/;
log_not_found off;
}
error_log /var/log/nginx/laravel_myproject_error.log;
access_log /var/log/nginx/laravel_myproject_access.log;
}
What I'm doing wrong?
That is odd, the artisan command should execute ngrok http --log stdout -host-header=myproject.dev 80
.
Can you confirm that this command is been executed, looking in the running processes?
And try to execute it instead of the artisan and see if the tunnel is working, the artisan command is just a helper to build and run this command.
The assets fix is made in the ServiceProvider
getting the x-original-host
and setting in the UrlGenerator
like in your example from StackOverflow, independent of how you started the ngrok.
I never tried ngrok with Docker, once I have time I will try to simulate using Docker, but I am quite busy, so it will take a while.
If you just need the assets fixed try to run the ngrok command the way you are used to do and see if it works, if don't work must be something different in Docker or dnsmasq.
@Sogl I tried ngrok with docker, running the ngrok inside the docker I got the same error, but running the ngrok in the host it works and the url inside the laravel was correct.
So I suggest you to run ngrok http -host-header=myproject.dev 80
in the host and the url will be correct since you have this package installed in your laravel app.
If you has the php cli in your host you can run php artisan ngrok myproject.dev
in the host, but it will just run the ngrok command as above, so there is no need to install php in the host just for it.
Closing this issue because it is a incompatibility between laradock/docker and ngrok.
If someone need to share a laravel app inside docker please run the ngrok in the host system like this example ngrok http -host-header=example.test 80
This package will fix the url inside the laravel app independent of how the ngrok was started.
Ok, thx. I tried your packege because of assets errors. Now I use ngrok like you described.
Describe the bug Error message when I try to connect to ngrok URL:
To Reproduce Steps to reproduce the behavior:
php artisan ngrok
*.ngrok.io
.Expected behavior Want to see my site with loaded assets (css, js).
Additional context I try your library in figth with this problem: https://stackoverflow.com/questions/50194923/laravel-and-ngrok-url-domain-is-not-correct-for-routes-and-assets
Usually I use
ngrok http -host-header=myproject.dev 80
command in host machine (not in Docker). I have correct redirects in hosts file.