Connect Device to Mac localhost Server? [closed]

2019-01-30 01:33发布

How do I allow any device, e.g., iPhone, to connect over a WLAN to my Mac's localhost server?

On my Mac, I'm running a "Hello World" HTTP Node.js server that serves a page, which Safari opens successfully, at http://localhost:1337. And, running ipconfig getifaddr en1 in Terminal outputs 192.168.1.9.

But, Safari, on both iPhone & Mac, displays "Safari can't connect to the server" when it tries to open http://192.168.1.9:1337.

I don't think this should involve port forwarding because I only want the HTTP server to be available privately, not publicly.

Related:

14条回答
叛逆
2楼-- · 2019-01-30 01:44

I had the same problem. I turned off my WI-FI on my Mac and then turned it on again, which solved the problem. Click Settings > Turn WI-FI Off.

I tested it by going to Safari on my iPhone and entering my host name or IP address. For example: http://<name>.local or http://10.0.1.5

查看更多
相关推荐>>
3楼-- · 2019-01-30 01:44

Have your server listen on 192.168.1.9:1337, not localhost:1337, i.e., 127.0.0.1:1337.

查看更多
Lonely孤独者°
4楼-- · 2019-01-30 01:47

MacOS Sierra users can find their auto-generated vanity URL by going to System Preferences > Sharing and checking beneath the Computer Name text input. To access it, enter this URL, plus your port number (e.g. your-name.local:8000), on your iPhone over the same Wi-Fi connection as your computer.

查看更多
闹够了就滚
5楼-- · 2019-01-30 01:49

make sure you phone and mac machine both connected to the same wifi and you good to go your http://<machine-name>.local

查看更多
迷人小祖宗
6楼-- · 2019-01-30 01:55

Try enabling Internet Sharing:
Open System Preferences -> Sharing. Check Internet Sharing to turn it on, it will prompt you to confirm your action, select ok. If your iPhone is connected using USB, the iPhone USB is checked at the "sharing your connection" list on the right side.
After this, try accessing your local server using your macs ip on wifi.

查看更多
小情绪 Triste *
7楼-- · 2019-01-30 01:55

I suggest to use the name of the computer, e.g.http://mymac:1337/. Works for me perfect without any configuration required and I don't have to care about changing IP addresses due DHCP.

查看更多
登录 后发表回答