Nginx – Unicorn setup for rails appliaction

————install nginx————
sudo apt-get install nginx
————start start————-
sudo service nginx start

others commands:
sudo service nginx restart
sudo service nginx stop

————install unicorn————
* add unicorn to your gem file

gem ‘unicorn’
bundle

————-setup unicorn————-

**1 add file to your application in config/unicorn.rb

cmd: vim config/unicorn.rb

**2 copy the folling template to the same file
https://github.com/defunkt/unicorn/blob/master/examples/unicorn.conf.rb

**3 edit the following changes to the same file
*1 working_directory – change the working directory to your application from root path
eg: working_directory “/home/vagrant/code/application”

*2 listen – change the listen socket to your application socket
eg: listen “/tmp/unicorn.application_name.sock”, :backlog => 64

*3 listen port – change the listening port to the port which you have open eg 8080
eg: listen 8080, :tcp_nopush => true

*4 pid – change the pid to your application pid
eg: pid “/home/vagrant/code/application_name/tmp/pids/unicorn.pid”

*5 stderr_path, stdout_path – change the log files
stderr_path “/home/vagrant/code/application_name/log/unicorn.log”
stdout_path “/home/vagrant/code/application_name/log/unicorn.log”

—————setup nginx—————–
note: change the application name to your app name

**1 open the nginx config file in vim
cmd: sudo vim /etc/nginx/sites-available/default

**2 add the following code to the file above server

upstream billing{
server unix:/tmp/unicorn.application_name.sock fail_timeout=0;
}
**3

Leave a comment