Can't access localhost with vagrant port forwarding where using Laravel on Mac

159 Views Asked by At

I can access the web server in vagrant via http://homestead.test. But some static files is compiled by Vite, which should be access by http://127.0.0.1:5173. So I add ports in Homestead.yaml

ports:
    - send: 33060 # MySQL/MariaDB
      to: 3306
    - send: 5173
      to: 5173

Fail. The most weird thing is that I can connect mysql via 33060 from mac, which means port forwarding is working. Then, why 5173 fails?

iptables -L comes out nothing

Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain FORWARD (policy DROP)
target     prot opt source               destination
DOCKER-USER  all  --  anywhere             anywhere
DOCKER-ISOLATION-STAGE-1  all  --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere             ctstate RELATED,ESTABLISHED
DOCKER     all  --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

Chain DOCKER (1 references)
target     prot opt source               destination

Chain DOCKER-ISOLATION-STAGE-1 (1 references)
target     prot opt source               destination
DOCKER-ISOLATION-STAGE-2  all  --  anywhere             anywhere
RETURN     all  --  anywhere             anywhere

Chain DOCKER-ISOLATION-STAGE-2 (1 references)
target     prot opt source               destination
DROP       all  --  anywhere             anywhere
RETURN     all  --  anywhere             anywhere

Chain DOCKER-USER (1 references)
target     prot opt source               destination
RETURN     all  --  anywhere             anywhere
1

There are 1 best solutions below

1
Andrija Antanaskovic On

Maybe it's because you have the same port number on both sides. What if you try to change one of them? Regarding MySQL/MariaDB, the first port is 33060, and the second is 3306, and it works. So,I would try it first. Hope this helps! :)