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.
Jamie van Dyke has his cheese solution and topfunky provided all his Nginx scripts, but I wanted something I could use to easily add new sites. Without thinking.
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.
Check the README for anything I may have missed. Source is right here. SVN? svn://errtheblog.com/svn/projects/nginx_config_generator.
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.)
whoa indeed. this looks very nice, I was just thinking about giving nginx a spin over the weekend, this has definitely bumped it up my todo list now!
I especially like the no-BS format for the yaml file, i’m thinking that it would be useful to be able to emit lighty or apache configs based on these files as well…
That example config is the most beautiful config for such hijinx. Apache and all its mods scare me. Make me timid like a small deer on a freeway. This nginx and your config are lovely.
Awesome. I had been using Apache2 because it is so nicely integrated into the deprec gem, but this got me up and running on nginx in under 5 minutes. Sweet.
Here’s the script I use to rebuild my Nginx config: right here. It’s for Gentoo so you may need to tweak it a bit, but it’s handy.
This is very, very nice. Thanks for sharing! I moved all my clients’ sites over from Apache to Nginx several months ago and I couldn’t be happier. This little gem should make it a lot easier to maintain them! Thanks again!
Nice. I need more nginx in my life. HTTP is dead, long live HTTP!
I love you guys. I needed something like this. :D
“Nginx Config like Holy Crap”
This is ridiculously fun.
You could also use this with the nginx include directive, and just copy over a template of your vhost and keep the default config global on the server, seems a bit nicer to me since its pretty modular.
I use vhost templates with only an upstream and server section, then do a include /etc/nginx/vhosts/*.conf
very nice Chris. I am just curious how you manage your mongrel_cluster config. Do you have as well a script that reads your config.yml to generate the mongrel_cluster.yml at deploy time ?
Freaking awesome!
+1 vote for SSL goodness baked into this plugin!
Thank you for this nice piece of software! I was able to switch to nginx in about 5 minutes using your generator.
I modified the template a bit to include feedburner aware rewrites and some config path changes.
Config file generation is fun. It remindes me of the the m4 macros for sendmail.cf files… with one difference: Both the yaml file and the resulting nginx.conf are readable ;-)
Whats wrong with Lighttpd? It is there much longer, and is really stable and widespread and has the same speed I believe.
what is wrong with lighty? http://mongrel.rubyforge.org/docs/lighttpd.html “’m sad to say that I have to recommend people not use lighttpd anymore. The author hasn’t updated the mod_proxy plugin and isn’t providing too much support for the bugs it has. If you’re running lighttpd and you constantly see 500 errors that are never recovered, then you should switch to Apache or another web server that can handle properly balancing backends.”
nginx just works…
Awesome work. I love it.
Howeever 1.1 released a few days ago is borken. I’d sign up with lighthouse but that would consume another 56 seconds of my time-boxed life.
duece:~/nginx/conf tim$ generate_nginx_config nginx.yml (erb):184: compile error (SyntaxError) (erb):184: syntax error, unexpected $end, expecting kEND
Tried it on 1.8.5 and 1.8.6.
1.0 works fine and I downgraded.
One suggestion. If a filename isn’t given, pipe it to stdout. In fact, you might want to consider taking out support entirely for writing to a destination file. Just let the user shell redirect it.
amazing nginx support www.nginxhosting.com
I use the nginx 0.5.35 replace apache on my centos server . The centos major job is rum phproxy . Nginx is good than Apache in my experience.
Hi, the link to the example file produces a 404 (http://require.errtheblog.com/projects/browser/nginx_config_generator/lib/config.yml.example?format=raw).
And I can’t generate the example config file on Ubuntu Server 7.10 (Gutsy Gibbon). Looks like it’s not recognising the—example flag, and is looking for a file by that name instead.
Hi! The link to the example config file is still broken (http://require.errtheblog.com/projects/browser/nginx_config_generator/lib/config.yml.example?format=raw)
The gem seems to be hosted on github now (shock!):
http://github.com/defunkt/nginx_config_generator/tree/master
Chime in.