[iphone] Connect Device to Mac localhost Server?

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:

This question is related to iphone localhost lan wifi localserver

The answer is


Tried everything on this page, but http://<name>.local:<PORT> only worked on my iPhone after I quit and restarted Safari...


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


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.


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.


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.


As posted I followed moeamaya's answer but needed to modify it just a bit to see my work in the Sites directory.

http://[name].local.~[username]/

[name] is as stated already (System Preferences/sharing/"Computer Name")

[username] is found at:

/etc/apache2/users/username.conf

hope this helps!


My problem was the same, but the solution had to do with changing a firewall setting. It turned out that node was set to block incoming traffic. I knew something was up because I used to be able to get to my localhost server from my phone.

Go to System Preferences -> Security & Privacy -> Firewall -> Firewall Options, and then scroll down until you find node and make sure node's setting is set to Allow incoming connections.

After changing the setting, I could reach the localhost server (port 3000) running on my Mac by going to http://192.168.1.11:3000


Always use the IP that is shown in your Network settings. It changes when you change location and you use another wireless connection.

For example in my case now it is: 10.0.0.5


I was only able to access my iphone using http://name.local:1337. You have to add the ".local" You can find your computer name under System Preferences/sharing/"Computer Name".


  1. Connect your iPhone to your Mac via USB.

  2. Go to Network Utility (cmd+space and type "network utility")

  3. Go to the "Info" tab

  4. Click on the drop down menu that says "Wi-Fi" and select "iPhone USB" as shown here:

    Photo for Step 4

  5. You'll find an IP address like "xxx.xxx.xx.xx" or similar. Open Safari browser on your iPhone and enter IP_address:port_number

    Example: 169.254.72.86:3000

[NOTE: If the IP address field is blank, make sure your iPhone is connected via USB, quit Network Utility, open it again and check for the IP address.]


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


I solve a similar problem.

  • connected Mac and iPhone to the same Wi-Fi
  • change the iPhone Wi-Fi setting, set http proxy to manual and change the Server to you Mac ip address and setting the Port. My Port is 80.

image one

image two

  • you can input http://<Mac ip>:<your customer server port> in iPhone's safari

also, make sure the server is listening for ur mobile device! for example, by default jekyll only answers requests made by the host machine. this solved my problem:

Connect to a locally built Jekyll Server using mobile devices in the LAN


Examples related to iphone

Detect if the device is iPhone X Xcode 8 shows error that provisioning profile doesn't include signing certificate Access files in /var/mobile/Containers/Data/Application without jailbreaking iPhone Certificate has either expired or has been revoked Missing Compliance in Status when I add built for internal testing in Test Flight.How to solve? cordova run with ios error .. Error code 65 for command: xcodebuild with args: "Could not find Developer Disk Image" Reason: no suitable image found iPad Multitasking support requires these orientations How to insert new cell into UITableView in Swift

Examples related to localhost

Xampp localhost/dashboard Set cookies for cross origin requests Invalid Host Header when ngrok tries to connect to React dev server How to turn on/off MySQL strict mode in localhost (xampp)? What is IPV6 for localhost and 0.0.0.0? How do I kill the process currently using a port on localhost in Windows? How to run html file on localhost? Can't access 127.0.0.1 Server http:/localhost:8080 requires a user name and a password. The server says: XDB How to solve ERR_CONNECTION_REFUSED when trying to connect to localhost running IISExpress - Error 502 (Cannot debug from Visual Studio)?

Examples related to lan

How to enable local network users to access my WAMP sites? Connect Device to Mac localhost Server? How to access my localhost from another PC in LAN? Error when trying to access XAMPP from a network

Examples related to wifi

java.net.ConnectException: failed to connect to /192.168.253.3 (port 2468): connect failed: ECONNREFUSED (Connection refused) use "netsh wlan set hostednetwork ..." to create a wifi hotspot and the authentication can't work correctly Get SSID when WIFI is connected " netsh wlan start hostednetwork " command not working no matter what I try Enabling/Disabling Microsoft Virtual WiFi Miniport Connect Device to Mac localhost Server? How to calculate distance from Wifi router using Signal Strength? Connect Android to WiFi Enterprise network EAP(PEAP) Enabling WiFi on Android Emulator Android turn On/Off WiFi HotSpot programmatically

Examples related to localserver

Connect Device to Mac localhost Server?