Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access localhost on mobile when using Jekyll

Tags:

server

jekyll

So I've searched google a lot, and I've tried everything everyone is suggesting but nothing seems to be working.

I want to view my jekyll website on my mobile.

When I run jekyll it says server address: 127.0.0.1:4000

My computer's IP is 154.135.X.Y

I've opened up the port in the windows inbound rules

I've tried accessing from my mobile using both 154.135.X.Y:4000 and 127.0.0.1:4000 but to no avail.

Anyone know how I can access my jekyll site on mobile?

like image 443
mildrenben Avatar asked Jan 21 '15 13:01

mildrenben


People also ask

Can you access localhost from mobile?

You can access your host machine with the IP address "10.0. 2.2". This has been designed in this way by the Android team. So your webserver can perfectly run at localhost and from your Android app you can access it via "http://10.0.2.2:8080".

How can I access my localhost application from anywhere?

For Windows users, you'll need to make sure you have Python installed first. For macOS and Linux, you can use a simple cURL command to install it straight from your command line. It'll run through and sign you up to the service if you're not already signed up. Then you'll have localhost up and running for the world!


2 Answers

If your server address is 127.0.0.1 it means Jekyll is only listening on your localhost. You'll need to start Jekyll and instruct it to bind to port 4000 on ANY interface:

jekyll serve --host 0.0.0.0
Configuration file: none
Auto-regeneration: enabled for '/private/tmp/test'
Configuration file: none
    Server address: http://0.0.0.0:4000/
  Server running... press ctrl-c to stop.

If you are accessing the computer from the web, you'll need to make sure your router forwards port 4000 to your PC.

If you are accessing the computer from your local LAN, make sure you accessing the private IP of your computer, and not the public IP.

Obviously you need to make sure there's not firewall that blocks incoming connections on your PC as well.

like image 103
m1keil Avatar answered Sep 21 '22 05:09

m1keil


  • run bundle exec jekyll serve --host 0.0.0.0 or jekyll serve --host 0.0.0.0
  • open port 4000 in your laptop. (For windows add inbound rules exception for port 4000.)
  • Find local ip address of laptop (https://www.whatismybrowser.com/detect/what-is-my-local-ip-address) like 192.168.1.109
  • make sure mobile is connected to same wifi network as laptop. Open local-ip-address-laptop with port 4000 in mobile browser. i.e. https://192.168.1.109:4000
  • Tada!
  • You would still be able to access the site in your laptop with http://127.0.0.1:4000

TiP: use {{site.baseurl}}/ to add images/assets in the pages and make sure there's no url:~ key in _config.yml

like image 21
GorvGoyl Avatar answered Sep 22 '22 05:09

GorvGoyl