Cannot access localhost:8080 from laravel

2019-07-19 18:11发布

问题:

I have a PHP application running on homestead box. This application makes calls to another app that is running on glassfish on my localhost:8080.

When PHP application sends the request to localhost:8080, I am getting following error:

ConnectException in RequestException.php line 49:
cURL error 7: Failed to connect to localhost port 8080: Connection refused

Still I can make calls to localhost:8080 from web browser.Anyone has any suggestion?

回答1:

Seeing how your application is running in Homestead (which by default is available on 192.168.10.10 and is forwarded to also be accessible on localhost:8000) your application running on Glassfish will not have access to it using localhost:8080. This is because localhost in your vagrant box (Homestead) is not actually the same localhost as on the host machine.

What you could do is grab the ip address from the host machine and connect to it from your application running in Homestead.



回答2:

So here is how I could solve the problem. Vagrant is the guest machine running on my localhost as host machine. To access host from guest, you need to use gateway from VB.

I found this answer which helped me to access my application on localhost.