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

2

105

After using jekyll serve on one machine, a WEBrick server is set up and the site can be accessed from localhost:4000 on this particular PC.

However, I'm wondering how to access this web server from other machines in the LAN, especially for mobile devices? I'm trying to test the jekyll site on mobile devices before pushing the code to Github.

Kweiyang answered 17/5, 2013 at 11:59 Comment(0)
W
216

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

Warrantable answered 17/5, 2013 at 12:11 Comment(7)
First part worked as indicated (jekyll 2.5.3), did not test second part (about entry in config file).Motorcar
To then access your site, on your other computer / mobile device, type in the ip of the computer doing the hosting. (Something probably like 192.168.1.5:4000). And here's a way to find your ip: https://mcmap.net/q/41138/-how-to-get-the-primary-ip-address-of-the-local-machine-on-linux-and-os-x-closedFibrovascular
If you're trying to run a server on Chromebook under Crouton you will also have to run /sbin/iptables -P INPUT ACCEPT to open the firewall. Optionally add this line to /etc/rc.local if you want the firewall to be open by default when you enter chroot. See also official instructions.Gilliland
but it's crashing all images with {{site.url}} because they are pointing to http:0.0.0.0:4000 which is not opening in main machineFigurehead
Setting this up in _config.yml worked perfect for me.Cleaver
This doesn't answer the question fully, what's the address to use? localhost:4000 or 0.0.0.0:4000 or something else?Gradin
@Andy, it's the LAN IP address of your PC, for example 192.168.0.100:4000.Boarfish
S
-7

Assuming your mobile device is connected to the same LAN as your development machine.

  1. Assertain the LAN IP address of your development machine. Usually something like: 192.168.0.XXX. Where .XXX is the unique last 3 digits of your dev machine's LAN IP.

  2. Point your mobile device's web browser to: http://192.168.0.XXX:4000

That's how I do it on my laptop and iPhone for Jekyll dev.

Sorensen answered 18/5, 2013 at 22:11 Comment(5)
Do I need to specify --host=0.0.0.0 when starting the server? (I can't test it at the moment.)Kweiyang
@user1177636, nope, not necessary, just jekyll serve. That will launch the WebBrick server which will be avail to any local device or machine. BTW, I'm assuming you're running Jekyll >=1.0.0, the commands are different for older versions. Run jekyll --server if using <= 0.12.1.Sorensen
Somehow it didn't work for me without specifying --host=0.0.0.0. What were the Firewall settings you used to fix it?Lauraine
For me as well, running jekyll serve did not work. My mobile device was unable to access the server unless i rang jekyll serve --host=0.0.0.0. Anyone have an explanation for this?Hildegardhildegarde
@Hildegardhildegarde jekyll serve by default listens on localhost(127.0.0.1) it is only accessible via the loopback adaptor on the machine it is running on. by telling it to bind to 0.0.0.0 you are telling it to bind to all interfaces, and thus it binds to your (ethernet/wireless/etc..) interface and thus is accessible via the lan side as well.Prepare

© 2022 - 2024 — McMap. All rights reserved.