Is it possible to serve multiple Jekyll sites locally?
Asked Answered
E

6

35

Every time I serve a Jekyll site from the command line it is served on port 4000. Two sites can't be served on the same port.

Is it possible to serve multiple Jekyll sites locally?

Elastomer answered 3/9, 2014 at 17:58 Comment(2)
The server in jekyll is no replacement for a dedicated server.Jebel
@user3791372, notice that the scope here is local.Elastomer
E
12

Yes it is possible to serve multiple Jekyll sites locally by setting different port numbers for each site using the Local Server Port serve command option.

See https://jekyllrb.com/docs/configuration/options/#serve-command-options.

Set a port number other than Jekyll's default port (4000) in the site's _config.yml file or when serving the site via the command line.

Elastomer answered 3/9, 2014 at 17:58 Comment(2)
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes.Congressman
Per the documentation, put e.g. port: 4001 in your _config.yml file.Congressman
B
41

You can also start the server with an additional argument --port 1234 or --host hostname. For example:

$ jekyll serve --port 4001 --host my_hostname_or_ip

You can view all the possible CLI flags from the official Jekyll documentation - https://jekyllrb.com/docs/configuration/options/#serve-command-options

Bulgar answered 22/6, 2017 at 7:30 Comment(1)
Hey, --port works not in all areas fine. The filter {% link %} will ignore the port. So links to pages on dev-env will be broken. Any idea to handle that?Drayman
E
12

Yes it is possible to serve multiple Jekyll sites locally by setting different port numbers for each site using the Local Server Port serve command option.

See https://jekyllrb.com/docs/configuration/options/#serve-command-options.

Set a port number other than Jekyll's default port (4000) in the site's _config.yml file or when serving the site via the command line.

Elastomer answered 3/9, 2014 at 17:58 Comment(2)
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes.Congressman
Per the documentation, put e.g. port: 4001 in your _config.yml file.Congressman
D
6

For multiple Jekyll sites, I just run this

bundle exec jekyll serve --port <your_port_number>

e.g

bundle exec jekyll serve --port 4001

Dex answered 27/2, 2019 at 6:28 Comment(0)
N
4

Two ways:

  1. In your _config.yml file, specify a port other than 4000 like this, for example:
    port: 4001
    
  2. OR (my preferred choice), add --port 4001 to your jekyll serve command, like this, for example:
    bundle exec jekyll serve --livereload --port 4001
    

From: https://jekyllrb.com/docs/configuration/options/#serve-command-options

enter image description here

Neap answered 30/12, 2020 at 19:13 Comment(0)
G
3

Open terminal, go to the Jekyll site directory and start the server

jekyll serve --port 4001

Go to another directory and start the second site

jekyll serve --port 4002
Gargle answered 16/7, 2018 at 14:32 Comment(0)
A
3

If you run it on mac docker client, provide host IP 0.0.0.0 will save your time a ton.

jekyll serve --port 4001 --host 0.0.0.0

By default, 127.0.0.1 is used for localhost and its NIC cannot receive any traffic from your mac host, whereas 0.0.0.0 means to accept traffic on all NICs

Arthurarthurian answered 23/12, 2019 at 7:18 Comment(1)
Just let me know the reason if you down-vote. I'd like to learn!Arthurarthurian

© 2022 - 2024 — McMap. All rights reserved.