How do you access a website running on localhost f

2019-01-02 16:40发布

I am working on a mobile website and would like to test it using my iPhone browser. My Windows 7 machine and iPhone are on the same wireless network. How do I access localhost from the iPhone? Right now I get a 404 error.

24条回答
时光乱了年华
2楼-- · 2019-01-02 17:16

If you're on a mac make sure to edit your /etc/hosts file. Find the IP address per instructions above and add the following line to that file

172.x.xx.x.x outer

After that, the steps above worked: navigate to the right page in my iphone browser, visit http://172.x.xx.x.x:port http://www.imore.com/how-edit-your-macs-hosts-file-and-why-you-would-want

查看更多
刘海飞了
3楼-- · 2019-01-02 17:18

If you are using Mac, go to System Preferences > Network and use your IP address instead of localhost. You can also use port number. In my case, I have a server running on port 1448 and I can preview 192.168.1.241:1448 using iPhone.

MacOsNetworkSettings

查看更多
心情的温度
4楼-- · 2019-01-02 17:22

you can try ngrok.io. Works on same principle as localtunnel.
Download the application for your os. and try to run like:

for linux:

./ngrok http 8000

8000 is port number your application is running on.

for windows:

 ngrok.exe http 8000
查看更多
看风景的人
5楼-- · 2019-01-02 17:22

If you go the route of going into your Network Settings and getting Wi-Fi IP address such as xxx.xxx.x.xxx:9000 (:9000 or whichever port is open), make sure your mobile device is also on that same Wi-Fi/signal IP address. I spent a day trying to get this to work and it didn't work until i switched my phone off the cellular network to the same Wi-Fi connection/IP address. Opened right up once I made this update.

查看更多
看淡一切
6楼-- · 2019-01-02 17:24

If you are not on the same network you could use this third party tool called localtunnel

http://localtunnel.me/

It basically routes your content through another server and you access that.

查看更多
柔情千种
7楼-- · 2019-01-02 17:25

If You'd Rather Type A Hostname Instead of IP Address

First Option (Quick Way):

You should be able to navigate to http://my-macbook-pro.local/mywebsite on your iPhone. See https://stackoverflow.com/a/9304094/470749

This approach tends to work because the '.local' domain is a special reserved word.

Second Option:

See http://xip.io/, which is a free service and is super convenient. No config necessary.

Then when you browse to http://mysite.app.192.168.1.130.xip.io (using a browser on your server or on any device on your LAN), it will show the page hosted at 192.168.1.130.

And if you're running Homestead on the machine that exists at that IP, browsing to http://mysite.app.192.168.1.130.xip.io:44300 (with the port in the URL) somehow shows the page hosted on the Homestead Vagrant virtual machine at 192.168.10.10. Pretty amazing.

Third Option (which doesn't depend on a service and is flexible but more complicated and only works if you have a router with DD-WRT on it):

If you have one local server hosting multiple different sites that you'd like to access via different hostnames (via iPhone), you can do this.

  1. In your OS, change the name of your computer to something short, meaningful, and easy to remember, such as "RYANDESK".
  2. In your DD-WRT router settings:
    1. In Services > Services > Static Leases, set the MAC address of your server to point to a specific IP address, such as 192.168.1.108. Set its hostname to be the same as you named your computer earlier. "Client Lease Time" can be 1440 minutes.
    2. Be sure to press Save and also Apply Settings with every change. ("Save" doesn't seem to automatically apply the settings.) If you get an error, it's probably because the GUI design of DD-WRT is misleading, and you unnecessarily pressed "Add" for Static Leases.
    3. In DHCP Server > User Domain, choose "LAN & WAN". For "LAN Domain", set it to some short string, such as your initials without any punctuation (e.g. "xyz"). Probably avoid using the word "local" since there might be conflicts. Don't use real-world domains such as "com", "org", "net", etc.
  3. In Services > Services > DNSMasq, enable DNSMasq and "Local DNS" and configure "Additional DNSMasq Options" to be something like: address=/project1.xyz/project2.xyz/192.168.1.108 (where xyz is whatever you chose in the earlier step, the IP points to the specific machine, and project1 and project2 are whatever hostname you want to point to each of those projects (such as different Nginx configs).
  4. Ensure that your HOSTS file doesn't have any entries conflicting with what we've done. If you don't know what a HOSTS file is, you're probably fine.
  5. Flush your DNS cache and release and renew your local IP. Switch into and out of Airplane Mode on iPhone to flush DNS cache there too.
  6. Now you can browse to http://ryandesk.xyz in your iPhone (or in your desktop browser), and it will resolve to your local server. So hopefully you've set up your Nginx or Apache or whatever to be listening for that hostname.

    https://wiseindy.com/it/how-to-access-your-pcs-using-dns-names-with-dd-wrt/ http://www.howtogeek.com/69696/how-to-access-your-machines-using-dns-names-with-dd-wrt/

查看更多
登录 后发表回答