laravelnginxvagranthomesteadbad-gateway

502 Bad Gateway nginx/1.21.1


Initial situation

Have a Laravel App on a Vagrant Box, Ubuntu 20.04 and Nginx, installed with Homestead.
I use browsersync to watch for file changes.

Issue

Suddenly I get a 502 Bad Gateway error at the URL localhost:3000, when npm run watch is running.

However if i do php artisan serve, the provided local url 127.0.0.1:8000 and the myproject.test domain are working correct if i open one of the url's in a browser.
But browsersync don't update this url's, it syncs only over localhost:3000.

Allready tried

Question

What can i do, to find out why i'm getting this error at localhost:3000 and at 127.0.0.1:8000 not?


Solution

  • You can use port forwarding to force data from VM ip to localhost but it's easier to just use virtual machine's ip.

    To take an IP of you virtual machine you can do this by one of these guides:

    (Linux)

    vagrant ssh -c "hostname -I | cut -d' ' -f2" 2>/dev/null

    (OS X)

    vagrant ssh -c "hostname -I | cut -d' ' -f2" 2>/dev/null | pbcopy

    The command for Linux also works for windows. I have no way to test, sorry. source:

    https://coderwall.com/p/etzdmq/get-vagrant-box-guest-ip-from-host

    After this, put an ip with ports which were specified for nginx in your browser.