Serve Multiple Jekyll Sites on Different Ports
I’ve reached the next level in my blog websites journey: there’s now 5 statically generated blogs I’m working on, meaning increasingly there’s a need to serve more than one at once for previewing pages in browser.
Issue with Serving Multiple Jekyll Sites Simultaneously
Assuming you started with the same codebase, you probably have a default Jekyll config (or one taken from another website of yours) – which means they’ll be sharing same network details.
Here’s what happens when I try to launch another website with default config locally:
greys@mcfly:~/proj/glebreys.com $ bundle exec jekyll serve
Configuration file: /Users/greys/proj/glebreys.com/_config.yml
Source: /Users/greys/proj/glebreys.com
Destination: /Users/greys/proj/glebreys.com/_site
Incremental build: disabled. Enable with --incremental
Generating…
done in 0.406 seconds.
Auto-regeneration: enabled for '/Users/greys/proj/glebreys.com'
------------------------------------------------
Jekyll 4.0.0 Please append <code>--trace</code> to the <code>serve</code> command
for any additional information or backtrace.
------------------------------------------------
and when I’m rerunning with –trace, I can see more details:
greys@mcfly:~/proj/glebreys.com $ bundle exec jekyll serve --trace
Configuration file: /Users/greys/proj/glebreys.com/_config.yml
Source: /Users/greys/proj/glebreys.com
Destination: /Users/greys/proj/glebreys.com/_site
Incremental build: disabled. Enable with --incremental
Generating…
done in 0.32 seconds.
Auto-regeneration: enabled for '/Users/greys/proj/glebreys.com'
bundler: failed to load command: jekyll (/usr/local/lib/ruby/gems/2.6.0/bin/jekyll)
<strong>Errno::EADDRINUSE: Address already in use - bind(2) for 127.0.0.1:4000</strong>
/usr/local/Cellar/ruby/2.6.5/lib/ruby/2.6.0/socket.rb:201:in bind' /usr/local/Cellar/ruby/2.6.5/lib/ruby/2.6.0/socket.rb:201:inlisten'
/usr/local/Cellar/ruby/2.6.5/lib/ruby/2.6.0/socket.rb:764:in block in tcp_server_sockets' /usr/local/Cellar/ruby/2.6.5/lib/ruby/2.6.0/socket.rb:227:ineach'
/usr/local/Cellar/ruby/2.6.5/lib/ruby/2.6.0/socket.rb:227:in foreach' /usr/local/Cellar/ruby/2.6.5/lib/ruby/2.6.0/socket.rb:762:intcp_server_sockets'
How To Serve Multiple Jekyll Sites
Edit the _config.yml file for your next Jekyll site and add port parameter, specifying next available port – perhaps after 4000 (which is the default). I chose number 4002:
title: Gleb Reys
logo: # Logo Image URL
description: Unix admin. Apple user. Photography enthusiast.
baseurl: '' # The subpath of your site, e.g. /blog
url: '' # The base hostname & protocol for your site
twitter: https://twitter.com/glebreys
facebook: https://www.facebook.com/gleb.reys
github: https://www.github.com/greys
instagram: ''
<strong>port: 4002</strong>
plugins: [jekyll-paginate, jekyll-redirect-from]
and so when I restart this second Jekyll site, it now starts just fine, binding to port 4002 instead of the default 4000:
greys@mcfly:~/proj/glebreys.com $ <strong>bundle exec jekyll serve</strong>
Configuration file: /Users/greys/proj/glebreys.com/_config.yml
Source: /Users/greys/proj/glebreys.com
Destination: /Users/greys/proj/glebreys.com/_site
Incremental build: disabled. Enable with --incremental
Generating…
done in 0.33 seconds.
Auto-regeneration: enabled for '/Users/greys/proj/glebreys.com'
Server address: http://127.0.0.1:4002/
Server running… press ctrl-c to stop.