Web Server Config Generator

Installation:

# gem install web_server_config_generator

First Run:

# web_server_setup /path/to/projects_dir

I got tired of setting up vhosts for new rails projects, and jumping through hoops to get vhosts for different environments working under the same webserver. So, point this script at your projects directory and it’ll generate all the necessary nginx config files for you to access all of your projects.

Here’s a rundown of how it works:

You’ve got a projects directory:

/Users/me/projects

Inside there you have a bunch of stuff, some of which are rails projects, maybe even some relative root url projects:

projects/
  bouncy_balls/
  shooter_mc_blasty_pants/
  lib_intent/
  drug_wars/
  super_awesome_site_o_many_apps/
    bb -> ../bouncy_balls/public
    pew_pew -> ../shooter_mc_blasty_pants/public

Now, the first time you run this script you’ll tell it where your projects directory is by either cd’ing there, or passing the path as the first argument:

# web_server_setup /Users/me/projects

It’ll prompt you to create an initial configuration including where your projects directory resides. This is by default at $HOME/.webconfig.

In that folder full of useful files it will generate some symlinks to allow each project to run in a different environment, as well as an individual config file for each project/environment combination. You don’t really need to worry about all that though because in the end…

You just have to run the script and point it at new project directories and it’ll create a config file for that project that you can edit to suit your needs. From that point on you can just run web_server_setup without arguments and it’ll generate all the necessary web server conf files for all projects with a config file.

The script then prints out a line that you’ll copy into your nginx.conf file that takes care of loading up all of your configuration.

The other piece of the puzzle this script takes care of is hostname resolution. Assuming you have the ‘ghost’ gem installed you’ll be prompted to add all of the generated host names to ghost.

So, once all that’s done you can reload nginx and fire up your trusty browser, visiting:

http://drug-wars-development.local

And whammy, blammy, it’s your app. Let’s have another:

http://super-awesome-site-o-many-apps-production.local/shooter_mc_blasty_pants

Wowie, zowie, relative root url stuff works too.

But wait there’s more, you’re developing along, and you see something weird, and you want to pair up with bob to check it out. It’s a hassle to reproduce, but that’s ok, you can just point bob to your box because we’re also listening on a generated port number. A quick look at the drug_wars config file (.webconfig.yml) and we see it is running in development on port 45397, so bob can just browse to your machine on that port and bingo, he’s looking at the same data as you.

Now you can point your tests at the test environment of an app and run your tests against nginx for speedier testing as well.

And the next time you create a new project? You can run this script from that project directory, or pass that directory as the first argument and we’ll only generate the files for that project. Of course you can also run from, or pass in, your projects directory again and we’ll generate anything that isn’t already generated, as well as show you things that have changed.

Relative Root Url Apps

Check out the example at the top of a newly genereated .webconfig.yml file for a project to see how you configure relative root apps.