Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access local site with subdomain on iPhone

I understand that you can access your computer's local site from a mobile device running on the same network by entering your computer's IP address (with relevant local port) into the address bar. However, I often use subdomains for development. On my local I access subdomains using lvh.me. For example:

blog.lvh.me

However, this will not work for mobile because lvh.me is redirecting to the IP 127.0.0.1 .

Is there a way to access a subdomain on an IP address? Essentially, doing the same thing as the above code but allowing for a dynamic IP address depending on the IP my computer has at the time?

like image 905
Duncan Walker Avatar asked Apr 17 '14 15:04

Duncan Walker


People also ask

How do I view a localhost website on my iPhone?

Running localhostNavigate to http://yourname.local:8000 on your phone and you're all set!

Can you add subdomain to localhost?

You need to set your /etc/hosts or C:\Windows\system32\drivers\etc\hosts (as administrator) to reflect the "subdomain". So add 127.0. 0.1 dev. localhost to either file (depending on your platform).

How do I access my subdomain?

Accessing the Subdomain MenuLog in to your Just Host cPanel account. Click the Domains tab at the top of your account. Click On Subdomains on the submenu.


1 Answers

So, after continuing research, I found an awesome tool that allows for exactly the above functionality:

xip.io

For example, if my computer has the IP address of 124.4.1.3 and I was running a web server at blog.lvh.me, where lvh.me redirects to localhost or 127.0.0.1, I could access my computer's localhost from another device on the network using blog.124.4.1.3.xip.io

I hope that helps someone!


Sidenote: The app in question was running on a rails server and the above setup required the following setting to be added to the environments/development.rb file:

config.action_dispatch.tld_length = 5

As rails was running on port 3000, this also required a url like:

blog.124.4.1.3.xip.io:3000

like image 168
Duncan Walker Avatar answered Sep 16 '22 21:09

Duncan Walker