Skip to main content

Installing nginx with passenger and RVM

In this post I am going to tell you how to install the nginx server with passenger to host rails applications.

Following are my configurations:
OS: Ubuntu 11.10
Ruby: 1.8.7
I am using RVM
Don't install nginx with sudo apt-get install nginx command, I face lot of problems with it..
First install Ruby 1.8.7 with RVM
Next install passenger which ever version you want, I prefer latest.
gem install passenger
The above command will install passenger for your system, now we can install either apache2 or nginx as HTTP servers. I am installing nginx here.
After installing passenger you need to run the following command
rvmsudo passenger-install-nginx-module
This is important step while installing, 
Don't run above command with sudo or without rvmsudo it won't work as expected.
The script will ask you if you want a default installation or a custom/advanced on.
I just did the default (option 1).
The script downloads and compiles nginx. It will ask you where you want it installed. I suggest /usr/local/nginx.
Don't just say /usr/local as that will create conf, html and logs directory right in /usr/local. You really want these in a nginx specific directory.
All being well the compilation and installation will go smoothly and your fresh installation of nginx will be modified for use with passenger.
If I remember the installation correctly it actually fires up nginx and leaves it running.
Check that with 'ps ax | grep nginx'
Go to your browser. 'http://localhost' should give a 'welcome to nginx' page. Look in /usr/local/nginx/logs/ for logging output.
ConfigurationI set up a symlink in /usr/local/sbin to the nginx binary so that it can be found in my regular PATH
sudo ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/nginx
You start nginx with 'sudo nginx' and shut it down with 'sudo killall nginx'. It needs to be run via sudo.
Configuring nginx is done in /usr/local/nginx/conf/nginx.conf and if you are used to Apache config files this will be a breath of fresh air. The main changes I made from the default was to set myself as the 'user' and set the worker_processes to 2. To set up a Rails application simply add a server block like this:
server {
listen 80;
root /Users/rvg/projects/test/public;
passenger_enabled on;
rails_env development;
Be sure to set the rails_env unless you are in production (the default) otherwise it will not work.
Restart nginx and with any luck you'll be able to access your application.
I made a few missteps doing my installation - such as thinking I needed to install nginx myself - but overall this went very smoothly.


Popular posts from this blog

Encrypting and Decrypting Query Strings in

Introduction We often pass values between pages in the form of a query string as key-value pairs. Query string is the easiest way and most widely practiced mechanism of transferring small pieces of data between web pages. The end-user may change the value in the query string to play around with the application, and at the same time, it leads to compromising the security and data integrity of the system. So the solution is encrypting the query strings. Following is the simple way of encryption and decryption mechanism in First I created two methods for encryption and decryption Encrypt the string private string Encrypt(string stringToEncrypt)          {              byte[] inputByteArray = Encoding.UTF8.GetBytes(stringToEncrypt);              byte[] rgbIV = { 0x21, 0x43, 0x56, 0x87, 0x10, 0xfd, 0xea, 0x1c };              byte[] key = { };              try              {                  key = System.Text.Encoding.UTF8.GetBytes("A0D1nX0Q");

Sending Email using your GMail Account in C#.NET

    Use System.Net.Mail namespace , not the deprecated System.Web.Mail . Doing SSL with System.Web.Mail will get security problems var client = new SmtpClient             {                 //create a host                 Host = "",                //gmail uses port number 587                 Port = 587,                //Enable Secure Communication                 EnableSsl = true,                 //Set delivery method to Network                 DeliveryMethod = SmtpDeliveryMethod.Network,                //Give the Credentials                 Credentials = new NetworkCredential("", "yourPassword"),                 //Set some timeout                 Timeout = 20000             };      //Create a MailMessage Object             using (var mailMessage = new MailMessage("", toE