Rails nginx Passenger on Ubuntu

Step Five—Install Passenger

Passenger is an effective and easy way to deploy Rails on nginx or apache. In this instance, we are going to run the nginx installation.

Once Ruby on Rails is installed, go ahead and install passenger.

gem install passenger 

Step Six—Install nginx

Here is where Passenger really shines. As we are looking to install Rails on an nginx server, we only need to enter one more line into terminal:

rvmsudo passenger-install-nginx-module
apt-get install nginx

And now Passenger takes over.

Passenger first checks that all of the dependancies it needs to work are installed. If you are missing any, Passenger will let you know how to install them, either with the apt-get installer on Ubuntu.

After you download any missing dependancies, restart the installation. Type: passenger-install-nginx-module once more into the command line.

Passenger offers users the choice between an automated setup or a customized one. Press 1 and enter to choose the recommended, easy, installation.

Step Seven—Start nginx

Passenger will take about five to ten minutes to install, configure, and optimize nginx with Ruby on Rails.

After it finishes, it will let you know about changes made to the nginx configuration file and how to deploy a Ruby on Rails application on your virtual server.

The last step is to turn start nginx, as it does not do so automatically.

 sudo service nginx start 

nginx is now on. You can see the exciting “Welcome to nginx” screen in your browser if you point it toward http://youripaddress/

Step Eight—Connect Nginx to Your Rails Project

Once you have rails installed, open up the nginx config file

sudo nano /opt/nginx/conf/nginx.conf

Set the root to the public directory of your new rails project.

Your config should then look something like this:

server { 
listen 80; 
server_name example.com; 
passenger_enabled on; 
root /var/www/my_awesome_rails_app/public; 
}

rails 后台启动

$ rails s -d

Usage: rails server [mongrel, thin, etc] [options]

    -p, –port=port                  Runs Rails on the specified port.

                                     Default: 3000

    -b, –binding=ip                 Binds Rails to the specified ip.

                                     Default: 0.0.0.0

    -c, –config=file                Use custom rackup configuration file

    -d, –daemon                     Make server run as a Daemon.

    -u, –debugger                   Enable the debugger

    -e, –environment=name           Specifies the environment to run this server under (test/development/production).

                                     Default: development

    -P, –pid=pid                    Specifies the PID file.

                                     Default: tmp/pids/server.pid