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:
- Accessing localhost from iPhone (in same network)
- https://superuser.com/questions/308451/connect-to-localhost-from-another-computer
- https://superuser.com/questions/400752/can-we-run-local-server-over-local-network-without-internet-access
- https://serverfault.com/questions/254947/accessing-localhost-xampp-from-another-computer-over-lan-network-how-to
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
orhttp://10.0.1.5
Have your server listen on
192.168.1.9:1337
, notlocalhost:1337
, i.e.,127.0.0.1:1337
.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.make sure you phone and mac machine both connected to the same wifi and you good to go your
http://<machine-name>.local
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.
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.