无法将本地 IP 地址映射到本地主机

Can't map local ip address to localhost

我有 2 个应用程序:

嗯,应用程序还没有说话...

我正在尝试从设备执行 POSThttp://192.168.1.34:3000/api/uploads,但我在 chrome 上得到 ERR_CONNECTION_REFUSED

因此,我尝试从计算机执行相同的请求,它 returns 相同 ERR_CONNECTION_REFUSED

当我从计算机上执行 http://localhost:3000/api/uploads 时,它工作正常。

所以,我认为本地 ip 没有映射到 localhost。我该怎么做?

我正在使用:

这是我的 /etc/hosts 文件的样子:

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       leansmac
127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost

ping 它也在工作:

ping 192.168.1.34                                                                                                               
PING 192.168.1.34 (192.168.1.34): 56 data bytes
64 bytes from 192.168.1.34: icmp_seq=0 ttl=64 time=0.091 ms
64 bytes from 192.168.1.34: icmp_seq=1 ttl=64 time=0.070 ms
64 bytes from 192.168.1.34: icmp_seq=2 ttl=64 time=0.138 ms

the mac and the phone are connected to the same wifi

我认为 Rails 不接受本地主机以外的外部连接是个问题。

请尝试以下操作:

Allow public connections to local Ruby on Rails Development Server

The simplest way requires no additional installations: just add a single option to your rails server (or rails s) command when you start up the server:

rails s --binding=0.0.0.0

The 0.0.0.0 address means "listen to requests from anywhere." On many systems, the default is 127.0.0.1, which means "listen to requests from localhost only." (If you don't also specify a -p or --port option, then the port shall be 3000, as usual.)