New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot set site.url to a different address than the --host flag address in development #5743

Closed
richardxia opened this Issue Jan 9, 2017 · 8 comments

Comments

Projects
None yet
4 participants
@richardxia

richardxia commented Jan 9, 2017

  • I believe this to be a bug, not a question about using Jekyll.
  • I updated to the latest Jekyll (or) if on GitHub Pages to the latest github-pages
  • I read the CONTRIBUTION file at https://jekyllrb.com/docs/contributing/
  • This is a feature request.

  • I am on (or have tested on) macOS 10+
  • I am on (or have tested on) Debian/Ubuntu GNU/Linux
  • I am on (or have tested on) Fedora GNU/Linux
  • I am on (or have tested on) Arch GNU/Linux
  • I am on (or have tested on) Other GNU/Linux
  • I am on (or have tested on) Windows 10+

  • I was trying to install.
  • There is a broken Plugin API.
  • I had an error on GitHub Pages, and I have reproduced it locally.
  • I had an error on GitHub Pages, and GitHub Support said it was a Jekyll Bug.
  • I had an error on GitHub Pages and I did not test it locally.
  • I was trying to build.
  • It was another bug.

My Reproduction Steps

When running jekyll serve --host 0.0.0.0, the site.url variable gets set to http://0.0.0.0:4000 when used in templates.

The Output I Wanted

I'd like to be able to set a site URL that is different from the network interface that the Jekyll server is listening to. I am doing development in a VM, so the hostname that I want my browser to see is different from the IP address/network interface that the Jekyll server is bound to. For example, since my VM has a host-only network interface at 192.168.33.10, I'd like to set http://192.168.33.10:4000 as the site URL that Jekyll renders so that any absolute URL still works, while still instructing Jekyll to listen on the 0.0.0.0 interface.

I understand that I can set --host 192.168.33.10, but one additional complication is that I am actually running Jekyll inside of a Docker container inside a VM. The Docker container won't allow any child processes to bind to 192.168.33.10.

/cc @jekyll/build

@DirtyF

This comment has been minimized.

Member

DirtyF commented Jan 9, 2017

It will not be set if you set JEKYLL_ENV=production and run jekyll serve.

@DirtyF DirtyF added the support label Jan 9, 2017

@richardxia

This comment has been minimized.

richardxia commented Jan 9, 2017

Is there any chance that this could be configurable for non-production environments? I'd like to not have to use JEKYLL_ENV=production in development, especially because I have a Google Analytics tracking ID that I've configured to only be used in production.

@DirtyF

This comment has been minimized.

Member

DirtyF commented Jan 9, 2017

You can define JEKYLL_ENV to whatever suits you the most, e.g. virtual, local URL override is only triggered when JEKYLL_ENV=development

@richardxia

This comment has been minimized.

richardxia commented Jan 9, 2017

I see, thanks, that workaround works for me. However, I am still a bit wary of using a different environment in the long term, since I don't know what other config values, if any, get set manually by Jekyll in the development environment.

@DirtyF

This comment has been minimized.

Member

DirtyF commented Jan 9, 2017

Another workaround is to override default url in a separate config file:
bundle exec jekyll serve --config _config.yml,_config_local.yml

@parkr

This comment has been minimized.

Member

parkr commented Jan 9, 2017

@richardxia If you're using a VM, I'd highly recommend setting up a separate webserver (nginx is very easy to install and setup) and using jekyll build --watch to regenerate your files. We have Docker images which do this.

We could whitelist 0.0.0.0 but we have gone back and forth with 127.0.0.1 and 0.0.0.0 a few times and I think we've finally settled on 127.0.0.1 for our "localhost". Using JEKYLL_ENV=virtual will not be problematic. If you search for "development" in this repo, you'll see that it's very infrequent for us to modify values based on the environment.

@richardxia

This comment has been minimized.

richardxia commented Jan 10, 2017

Thanks for the suggestion, @parkr. That solution seems straightforward enough for me to use. Since this is just a development VM, I think I'll use python -m SimpleHTTPServer 4000 instead of installing nginx, but the end result is same.

@ZiroKyl

This comment has been minimized.

ZiroKyl commented Dec 14, 2017

@richardxia, @parkr I simple run:
in terminal1: bundle exec jekyll build --watch
and
in terminal2: bundle exec jekyll serve --skip-initial-build --no-watch --host 0.0.0.0 --port 80 😉

#6034

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment