That documentation does mention:
It will not be set if you set JEKYLL_ENV=production
and run jekyll serve
.
If JEKYLL_ENV
is any value except development
(its default value), Jekyll will not overwrite the value of URL in your config.
And again, this only applies to serving, not to building.
So double-check your JEKYLL_ENV
value, and your command (jekyll serve
)
The OP points out to jekyll/jekyll
PR 7253 in jekyll v4.2.0
Local tests show that the local preview server is based on config["host"]
and config["port"]
values..
So even if config["url"] == https://jekyllrb.com
, the site will be served at the default setting: //127.0.0.1:4000
This simplifies users' workflow by not having to build the site again with JEKYLL_ENV=production
(unless their templates are designed to render differently for the two ENV vars, which is a different story altogether)
This, however, is in the process of being reverted: PR 8620
The documentation on jekyllrb.org was not updated to reflect this change in behavior,
That change did not affect cases where the local server URL was explicitly set via bundle exec jekyll serve --host localhost --port 4000
to be localhost:4000
, or when it was set to be any other combination of hosts or ports.
That change only affected the default jekyll serve
, which is the local development action recommended in the Jekyll docs.
So this could be a workaround in your case:
bundle exec jekyll serve --host localhost --port 4000