Connect to a Locally Built Jekyll Server Using Mobile Devices in the Lan

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

Try jekyll serve --host=0.0.0.0 when you invoke Jekyll on the command line.

That will make Jekyll's HTTP server bind to all available IPs, rather than just to localhost.

You can also add this to your _config.yml with host: 0.0.0.0. GitHub will simply ignore this when you push, so it's safe to use if you don't mind having your work openly accessible on your network.


Without --host=0.0.0.0 Jekyll will output something like this when you start up:

$ jekyll serve
[...]
Server address: http://127.0.0.1:4000/
Server running... press ctrl-c to stop.

But with --host=0.0.0.0 (or host: 0.0.0.0 in _config.yml) you'll notice that it's listening on all interfaces (represented by 0.0.0.0) rather than just listening on the loopback interface (represented by 127.0.0.1)

$ jekyll serve --host=0.0.0.0
[...]
Server address: http://0.0.0.0:4000/
Server running... press ctrl-c to stop.

If you still cannot access your server then there might be a firewall stopping it. Temporarily disable your firewall, or add a port forwarding rule for port 4000.


Once Jekyll is appropriately listening on all interfaces, you can access this from your mobile device using your LAN IP address (retrieved from something like ifconfig or ipconfig depending on your operating system).

How to host jekyll on a local network, so multiple people can access it?


Description:

While starting Jekyll Server, we can also setup some options to configure the IP address and also the port number of the site under development environment to host the website in local network. So if we want to change the IP from http://127.0.0.1:4000 to http://192.168.x.x:4000 (x= 0 to 255 any one number), we can set that in Jekyll server command! But for this, we will need to find out our current IP address at our current network which will help us to serve the website in local network.

So at first step:

We will open our terminal on our PC. For Android user, we need to open Termux app. Then simply type ifconfig to get the IP address of our device in the current network. We will get an output like this one (Here I'm using Android device for development. So output might be something different than this one on your PC terminal but the process is same):

$ ifconfig
Warning: cannot open /proc/net/dev (Permission denied). Limited output.
lo: flags=XX<UP,LOOPBACK,RUNNING> mtu XXXXX
inet 127.0.0.1 netmask 255.XXX.XXX.XXX
unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen XXXX (UNSPEC)
wlan0: flags=XXXX<UP,BROADCAST,RUNNING,MULTICAST> mtu XXXX
inet 192.168.1.103 netmask 255.XXX.XXX.XXX broadcast 192.168.1.255
unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen XXXX (UNSPEC)

X= some numbers with our device credentials which is dummied with this variable

If you are using a WiFi router then we will need the wlan0 part to get our device IP. Under wlan0 section there is a subsection of inet showing our current IP! YUP, we need that IP address 192.168.1.103! This might be different for your device and network. This is the key of this mission! Now we're going to the second important step.

So the Second Step is:

That required input command to configure the IP address.

jekyll s -H 192.168.1.103 -P 8080

Here:

  1. jekyll s for jekyll server
  2. -H 192.168.1.103 for bidding the IP address for customisation from the default IP http://127.0.0.1 which is our localhost address.
  3. -P 8080 for port setup. This part is optional. Default port is 4000.

This is the process of changing the localhost IP (http://127.0.0.1) to local network IP which will be available for other device of the same network user.

Now our Jekyll is available in our local network! Other users in the same network will also be able to visit the website while the server command is running. And the link will be http://192.168.1.103:8080 if you also configure the port number. Otherwise if you have used the command jekyll s -H 192.168.1.103 without port configuration the link will be: http://192.168.1.103:4000

Again: 192.168.1.103 was for my case, your IP address will be different for your device. That will be needed to use for your server and link address.

Make served Jekyll project accessible within local network

You can do this by starting the server with this:

bundle exec jekyll serve --host 0.0.0.0

You can then access the site locally by going to the servers IP and port 4000. It might look similar to this:

http://192.168.1.100:4000

Source: https://zarino.co.uk/post/jekyll-local-network/

Jekyll server not working in mobile browser

As you can observe in the Output: (Server address: http://127.0.0.1:4000/), Jekyll only answers request coming from the local machine.

To make Jekyll answer on all adresses, use the -H option. From jekyll serve --help:

-H, --host [HOST]  Host to bind to

use as follows:

jekyll serve --watch -H 0.0.0.0


Related Topics



Leave a reply



Submit