27.02.2013 Views

Rails%203%20In%20Action

Rails%203%20In%20Action

Rails%203%20In%20Action

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

408 CHAPTER 14 Deployment<br />

Once Rails has done its thing, it sends the request<br />

back up the chain, going through Passenger to nginx and<br />

then finally back to the client as the response—most commonly<br />

HTML but it could be anything, really.<br />

When you launch rails server, the process looks like<br />

figure 14.4.<br />

In this example, there’s only one instance of your<br />

application serving requests and so it’s going to be slower<br />

than having the Passenger pool of them serving it. Additionally,<br />

nginx is super quick at serving files (like your CSS<br />

and JavaScript ones) and handles these requests itself,<br />

without Rails knowing about it. When you run rails server, it serves every request,<br />

and is definitely not web scale. nginx and Passenger are designed for speed and reliability,<br />

and so you should feel pretty confident in using them.<br />

Enough talk, let’s get into this! You’re going to install the passenger gem now, and<br />

it’s nice enough to set up nginx for you too!<br />

14.6.1 Installing Passenger<br />

To install Passenger, as your user on the box (vagrant ssh, if Vagrant) you can run the<br />

same gem install you’ve been running all this time:<br />

gem install passenger<br />

Once this gem is installed, install nginx and the Passenger module by running this<br />

lovely command. The -i option “simulates initial login,” meaning that the RVM script<br />

will run before this command, making it available:<br />

sudo -i passenger-install-nginx-module<br />

At the prompt, press 1 for the install process to download and compile nginx automatically.<br />

When prompted for a directory (/opt/nginx), press Enter. This’ll be the directory<br />

your server runs from. After this, nginx will be compiled and installed. This<br />

process takes a minute or two, so go grab something to eat or drink, or stretch.<br />

Once it’s done, you’re told that Passenger inserted some configuration for you;<br />

wasn’t that nice of it?<br />

The Nginx configuration file (/opt/nginx/conf/nginx.conf)<br />

must contain the correct configuration options in order for Phusion Passenger<br />

to function correctly.<br />

This installer has already modified the configuration file for you! The<br />

following configuration snippet was inserted:<br />

http {<br />

...<br />

passenger_root /usr/local/rvm/gems/ruby-1.9.2-p180/gems/passenger-<br />

3.0.4;<br />

passenger_ruby /usr/local/rvm/wrappers/ruby-1.9.2-p180/ruby;<br />

...<br />

}<br />

client<br />

server<br />

Figure 12.4 Simplified<br />

client-server relationship

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!