对本地 laravel rest API 使用 http://192.168 地址

Using a http://192.168 address for a local laravel rest API

我正在从 laravel 7 升级到 laravel 8,我正在尝试向本地托管的 laravel API 发出 http 请求。如果我使用 http://localhost 或 http://127.0.0.1, the requests give a response. But if I use a http://192.168.x.x address, I get an error Error: connect ECONNREFUSED. How do I use http://192.168.x.x ?

https://i.stack.imgur.com/98Z1r.png

Access Laravel project over a network using IP

1- 确定您的 IP 地址

在 windows 配置

在 linux ifconfig

2-运行 你的项目 php artisan 服务 --host=192.168.1.10 --port=8000

3-通过浏览器访问您的项目(远程)

http://192.168.1.10:8000

可能的问题:

如果启用了防火墙,远程系统可能会阻止访问。 – 为此,您可以在本地系统上完全禁用防火墙 – 或者,启用某个端口 在linux允许一个端口

ufw状态 ufw 启用 8000