Nginx
My preferred way of installing nginx on OSX is using homebrew. You need to compile it with passenger support
1
| |
RVM
RVM makes it easy to manage multiple rubies. Installation is easy
1
| |
You can then install different versions of ruby. In this case let’s install Ruby Enterprise Edition
1
| |
Then we can make Ruby Enterprise Edition the default Ruby on this machine with
1
| |
Passenger
This is the most tricky part of the install. To start you’ll need the passenger gem
1
| |
We need to use the nginx source code for this process. If your homebrew setup is a default one run
1
| |
Note your version of nginx may be different from this!
Then we need to run the nginx passenger module installer
1
| |
The default install downloads an entirely new binary for Nginx - a bit annoying. If you choose option 2 you’ll be able to choose the source you’ve downloaded with homebrew. For the source directory choose the one we’ve just extracted
1
| |
Then choose to install Nginx to (if you’ve used the default homebrew install)
1
| |
Hit return on the next two prompts. Drink tea whilst it compiles.
The installer spits out some configuration for you. Open up /usr/local/etc/nginx/nginx.conf in your favourite text editor and paste this in.
Then you just need to create a virtual host
1 2 3 4 5 6 | |
Provided you’ve added foo.local to your /etc/hosts file you should be able to start the server and see your site using
1
| |
Running multiple virtual hosts
Passenger 3 adds a killer feature - the ability to run a standalone passenger and proxy using Nginx and TCP sockets. The process for this is to first setup a virtual host to proxy through to a socket
1 2 3 4 5 6 7 8 9 10 11 12 | |
Then start a standalone instance of Passenger. This downloads and complies a new binary of Nginx for some reason
1
| |
This is explained in more detail on the Phusion Blog. Because the standalone passenger is invoked within an RVM context it is completely possible to have different ruby versions and gemsets. TOTAL WIN!
It should then be trivial use something like Monit to make sure that the process for virtual hosts is running and start / stop it.
This setup can be applied to a Linux server too to create a flexible Rails stack with multiple hosts, Rubies and gemsets.