Add the following code in nginx.conf, inside http block
upstream rails {
# Path to Unicorn socket file
server unix:/home/username/project_name/shared/sockets/uni$
}
Install the gem
gem install unicorn
And then create unicorn.rb in your project inside config directory and put the content below
# set path to the application
app_dir = File.expand_path("../..", __FILE__)
shared_dir = "#{app_dir}/shared"
working_directory app_dir
# Set unicorn options
worker_processes 2
preload_app true
timeout 30
# Path for the Unicorn socket
listen "#{shared_dir}/sockets/unicorn.sock", :backlog => 64
# Set path for logging
stderr_path "#{shared_dir}/log/unicorn.stderr.log"
stdout_path "#{shared_dir}/log/unicorn.stdout.log"
# Set proccess id path
pid "#{shared_dir}/pids/unicorn.pid"
Create inside sites-available on nginx a file with the content below
server {
listen 80;
server_name localhost;
root /home/deploy/gerenciador_estudos;
try_files $uri/index.html $uri @rails;
location @rails {
proxy_pass http://rails;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
After that, create a symbolic link to sites-enable. Example
ln -s /etc/nginx/sites-available/project_name /etc/nginx/sites-enabled/project_name
To start Unicorn go inside your project and execute:
For development environment
sudo unicorn -c config/unicorn.rb -E development -D
Or, for production
sudo unicorn -c config/unicorn.rb -E production -D
To stop, execute:
sudo pkill unicorn