This gist shows how to setup and configure Rails application in Nginx on Centos.
Our application will be located in '/var/www/apps/mysite'.
After installing Passenger Nginx will be located in '/opt/nginx' directory.
Read this to install Passenger and Nginx on Centos.
Create configuration file '/opt/nginx/sites-available/mysite.conf' for server (virtual host) in Nginx:
server {
passenger_enabled on;
passenger_ruby /home/uadmin/.rvm/wrappers/ruby-2.1.5/ruby;
server_name mysite.com ;
root /var/www/apps/mysite/current/public;
rails_env production;
access_log /var/www/logs/mysite/access.log;
error_log /var/www/logs/mysite/error.log;
if (-f $document_root/system/maintenance.html) {
rewrite ^(.*)$ /system/maintenance.html break;
}
}
It assumes that Rails app will be running with Ruby 2.1.5. If you have different version of Ruby change the line passenger_ruby /home/uadmin/.rvm/wrappers/ruby-2.1.5/ruby;
to point to your Ruby binary.
It is useful if you have multiple ruby versions.
If you specify the same Ruby version in Nginx main config file then you don't need to have this line passenger_ruby ..
.
Find Nginx main config file in this gist below.
Create necessary directories:
mkdir /var/www/logs
cd /var/www/logs
mkdir mysite
Make the server enabled in Nginx:
sudo ln -s /opt/nginx/sites-available/mysite.conf /opt/nginx/sites-enabled/mysite.conf
Restart Nginx:
sudo service nginx restart