I’ve been using Nginx (engine-x) for some time now and really digg it. So much simpler and nicer than Apache. Ezra apparently discovered the thing, a hidden Russian gem in the endless desert of HTTP servers, sometime last year.
The problem I’ve been having is managing my vhosts. There’s probably a solution out there already, yeah. Adam Keys has one idea. It’s nice, and it even has Capistrano support, but it’s Rails centric. Cheat, Subtlety, and require are not Rails sites. I need a more global solution.
Here, take this:
$ sudo gem install nginx_config_generator
The nginx_config_generator is a gem which takes a YAML file of options for Nginx vhosts and spits out a complete Nginx-friendly config file. I’m using it for Err and other debaucherous apps hosted right here on this very machine.
Okay, get started:
$ generate_nginx_config ‐‐example > config.yml
This’ll create an example config file for you. Yep, YAML. It looks just like this.
Run the generator on that example config file and tell it what you want to call your nginx file. Like:
$ generate_nginx_config config.yml nginx.conf
If your out file (nginx.conf) already exists and you want to overwrite it, use the -y option.
The generator will respect two environment variables: NGINX_CONFIG_YAML and NGINX_CONFIG_FILE. These’ll make spittin’ out your modified config even easier.
If you have ideas for alternate options, I’d love to hear (and add) them. I’ll be growing what the config file supports as my nginx-fu grows stronger. For now this is all I’ve needed, but I can see SSL and alternate location declarations very clearly in the near future.
(Throw bugs at Lighthouse, please.) (Thanks.)