localhostjekylllocal-networkjekyll-theme

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


I was working on Jekyll to make a static site for my own blog which is totally coded in a Android phone. Using Termux, I'm able to setup and serve jekyll from my Android device.

But while serving the site locally, it was serving from Localhost IP (http://127.0.0.1:3000)! Where, I want to serve the site on my Local Network IP (http://192.168.x.x:3000). I get my IP address from the $ ifconfig command.

But how could I serve the site in the local network IP. So that, me and my other devices in my local network can also visit the site with the link.


Solution

  • 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.