SlideShare a Scribd company logo
Nginx vs Unicorn
2015/03/29 KhanhPham
Step1: Install nginx
1. Install nginx
sudo apt-get update
sudo apt-get install nginx
2. Display your ip
sudo service nginx start
Step1: Install nginx
3. Start nginx
sudo service nginx start
4. Create new config nginx for your app
sudo vim /etc/nginx/conf.d/sieunhac.conf
Step1: Install nginx
This is file sample config nginx
upstream sieunhac {
server unix:/tmp/sieunhac.sock fail_timeout=0;
}
server {
listen 80;
server_name 192.168.1.2;
root /home/khanhpn/Project/sieunhac_v1/public;
try_files $uri/index.html $uri @sieunhac;
location @sieunhac {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://sieunhac;
}
error_log /var/log/nginx/sieunhac_error.log;
access_log /var/log/nginx/sieunhac_access.log;
error_page 500 502 503 504 /500.html;
Step1: Install nginx
5. If you have nginx, you can remove all via this
command bellow:
sudo apt-get remove nginx nginx-full nginx-light nginx-naxsi nginx-common
Step2: Install unicorn
1. Go to your app, and add gem ‘unicorn’
2. Create new file config/unicorn.rb with
content as bellow:
Step2: Install unicorn
app_name = 'sieunhac'
root = "/home/khanhpn/Project/sieunhac_v1"
working_directory root
pid_file = "#{root}/tmp/pids/#{app_name}.pid"
stderr_path "#{root}/log/#{app_name}_stderr.log"
stdout_path "#{root}/log/#{app_name}_stdout.log"
old_pid = pid_file + '.oldbin'
pid pid_file
listen "/tmp/#{app_name}.sock", backlog: 64
listen(3000, backlog: 64) if ENV['RAILS_ENV'] == 'development'
worker_processes ENV['RAILS_ENV'] == "production" ? 5 : 3
preload_app true
timeout 60
before_fork do |server, worker|
if defined?(ActiveRecord::Base)
ActiveRecord::Base.connection.disconnect!
end
if File.exists?(old_pid) && server.pid != old_pid
begin
Process.kill("QUIT", File.read(old_pid).to_i)
rescue Errno::ENOENT, Errno::ESRCH
Step2: Install unicorn
3. Start unicorn via this command
bundle exec unicorn -E development -c
config/unicorn.rb
Step2: Install unicorn
4. Start unicorn via service of ubuntu
Create new file vim /etc/init.d/unicorn_sieunhac
Step2: Install unicorn
# Provides: unicorn
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Manage unicorn server
# Description: Start, stop, restart unicorn server for a specific application.
### END INIT INFO
set -e
# Feel free to change any of the following variables for your app:
TIMEOUT=${TIMEOUT-60}
APP_ROOT=/home/khanhpn/Project/sieunhac_v1
PID=$APP_ROOT/tmp/pids/sieunhac.pid
CMD="cd $APP_ROOT; bundle exec unicorn -D -c $APP_ROOT/config/unicorn.rb -E development"
AS_USER=khanhpn
set -u
OLD_PIN="$PID.oldbin"
sig () {
Step2: Install unicorn
5. Start unicorn via this command
sudo /etc/init.d/unicorn_sieunhac start

More Related Content

ODP
Elastic search
ODT
Squid file
PDF
Config websocket on apache
PDF
Aeon mike guide transparent ssl filtering
PDF
Aeon mike guide transparent ssl filtering (1)
PDF
PPS
Squidinstallation
PDF
Rdo mitaka
Elastic search
Squid file
Config websocket on apache
Aeon mike guide transparent ssl filtering
Aeon mike guide transparent ssl filtering (1)
Squidinstallation
Rdo mitaka

What's hot (18)

PDF
PPT
How To Deploy A Cloud Based Webserver in 5 minutes - LAMP
TXT
Commands
PDF
Step by-step installation of a secure linux web dns- and mail server
PDF
How To Install and Configure Apache SSL on CentOS 7
TXT
Intalacion de owncloud
PDF
How to Install MariaDB Server or MySQL Server on CentOS 7
PPTX
nginx + uwsgi emperor + bottle
PDF
Ajenti control panel
PDF
Jones_Lamp_Tutorial
PPTX
Installing hive on ubuntu 16
PPTX
Installing hadoop on ubuntu 16
PPTX
Simple webapps with nginx, uwsgi emperor and bottle
PDF
How to contribute Apache CloudStack
PPTX
Installing apache sqoop
PDF
Services: Web Webmail Proxy
PDF
bivou.ac
PDF
VPNaaS neutron
How To Deploy A Cloud Based Webserver in 5 minutes - LAMP
Commands
Step by-step installation of a secure linux web dns- and mail server
How To Install and Configure Apache SSL on CentOS 7
Intalacion de owncloud
How to Install MariaDB Server or MySQL Server on CentOS 7
nginx + uwsgi emperor + bottle
Ajenti control panel
Jones_Lamp_Tutorial
Installing hive on ubuntu 16
Installing hadoop on ubuntu 16
Simple webapps with nginx, uwsgi emperor and bottle
How to contribute Apache CloudStack
Installing apache sqoop
Services: Web Webmail Proxy
bivou.ac
VPNaaS neutron
Ad

Viewers also liked (6)

PDF
Tìm đường đi xe buýt trong TPHCM bằng Google Map
PDF
Subprogram
PDF
Untitled Presentation
PDF
Nhập môn công tác kỹ sư
PDF
Control structure
PPTX
Bus tracking application in Android
Tìm đường đi xe buýt trong TPHCM bằng Google Map
Subprogram
Untitled Presentation
Nhập môn công tác kỹ sư
Control structure
Bus tracking application in Android
Ad

Similar to How to install nginx vs unicorn (20)

PDF
ITB2019 NGINX Overview and Technical Aspects - Kevin Jones
PPTX
Nginx-deploy on linux server with 80 and 442
PDF
How to Set Up Nginx Server Blocks on Ubuntu 2404.pdf
PDF
Install nginx on ubuntu 21.04 server
PPTX
Nginx [engine x] and you (and WordPress)
PDF
Multiple django applications on a single server with nginx
PPT
Real World Rails Deployment
PDF
NGINX ADC: Basics and Best Practices – EMEA
PPTX
NGINX: Basics & Best Practices - EMEA Broadcast
PDF
NGINX: Basics and Best Practices EMEA
PDF
How to Get Started With NGINX
PPTX
Django Deployment-in-AWS
ODP
Introduction to Nginx
PDF
NGINX ADC: Basics and Best Practices
PPTX
Nginx A High Performance Load Balancer, Web Server & Reverse Proxy
PPTX
NGINX Installation and Tuning
DOC
Nginx 0.8.x + php 5.2.13 (fast cgi) setup web server
PPTX
NGINX: High Performance Load Balancing
PPTX
NGINX: Basics and Best Practices
PPTX
NGINX 101 - now with more Docker
ITB2019 NGINX Overview and Technical Aspects - Kevin Jones
Nginx-deploy on linux server with 80 and 442
How to Set Up Nginx Server Blocks on Ubuntu 2404.pdf
Install nginx on ubuntu 21.04 server
Nginx [engine x] and you (and WordPress)
Multiple django applications on a single server with nginx
Real World Rails Deployment
NGINX ADC: Basics and Best Practices – EMEA
NGINX: Basics & Best Practices - EMEA Broadcast
NGINX: Basics and Best Practices EMEA
How to Get Started With NGINX
Django Deployment-in-AWS
Introduction to Nginx
NGINX ADC: Basics and Best Practices
Nginx A High Performance Load Balancer, Web Server & Reverse Proxy
NGINX Installation and Tuning
Nginx 0.8.x + php 5.2.13 (fast cgi) setup web server
NGINX: High Performance Load Balancing
NGINX: Basics and Best Practices
NGINX 101 - now with more Docker

More from baran19901990 (17)

PDF
How to build a news website use CMS wordpress
PDF
Lexical
PDF
Introduction
PDF
Datatype
PDF
10 logic+programming+with+prolog
PDF
09 implementing+subprograms
PDF
08 subprograms
PDF
07 control+structures
PDF
How to install git on ubuntu
DOC
Ruby notification
DOC
Rails notification
DOC
Linux notification
PDF
PDF
DOCX
Báo cáo mô hình quản lý khách sạn
PPTX
MDA Framework
How to build a news website use CMS wordpress
Lexical
Introduction
Datatype
10 logic+programming+with+prolog
09 implementing+subprograms
08 subprograms
07 control+structures
How to install git on ubuntu
Ruby notification
Rails notification
Linux notification
Báo cáo mô hình quản lý khách sạn
MDA Framework

Recently uploaded (20)

PDF
Cloud-Scale Log Monitoring _ Datadog.pdf
PDF
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
PDF
Unit-1 introduction to cyber security discuss about how to secure a system
PPTX
INTERNET------BASICS-------UPDATED PPT PRESENTATION
PPTX
Funds Management Learning Material for Beg
PPT
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
PPTX
E -tech empowerment technologies PowerPoint
PDF
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...
PDF
FINAL CALL-6th International Conference on Networks & IOT (NeTIOT 2025)
PPTX
Introuction about ICD -10 and ICD-11 PPT.pptx
PPTX
Introduction to Information and Communication Technology
PDF
How to Ensure Data Integrity During Shopify Migration_ Best Practices for Sec...
PPTX
Introduction about ICD -10 and ICD11 on 5.8.25.pptx
PPTX
Digital Literacy And Online Safety on internet
PDF
The Internet -By the Numbers, Sri Lanka Edition
PDF
Slides PDF The World Game (s) Eco Economic Epochs.pdf
PDF
WebRTC in SignalWire - troubleshooting media negotiation
PPTX
Internet___Basics___Styled_ presentation
PPTX
Module 1 - Cyber Law and Ethics 101.pptx
PPTX
PptxGenJS_Demo_Chart_20250317130215833.pptx
Cloud-Scale Log Monitoring _ Datadog.pdf
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
Unit-1 introduction to cyber security discuss about how to secure a system
INTERNET------BASICS-------UPDATED PPT PRESENTATION
Funds Management Learning Material for Beg
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
E -tech empowerment technologies PowerPoint
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...
FINAL CALL-6th International Conference on Networks & IOT (NeTIOT 2025)
Introuction about ICD -10 and ICD-11 PPT.pptx
Introduction to Information and Communication Technology
How to Ensure Data Integrity During Shopify Migration_ Best Practices for Sec...
Introduction about ICD -10 and ICD11 on 5.8.25.pptx
Digital Literacy And Online Safety on internet
The Internet -By the Numbers, Sri Lanka Edition
Slides PDF The World Game (s) Eco Economic Epochs.pdf
WebRTC in SignalWire - troubleshooting media negotiation
Internet___Basics___Styled_ presentation
Module 1 - Cyber Law and Ethics 101.pptx
PptxGenJS_Demo_Chart_20250317130215833.pptx

How to install nginx vs unicorn

  • 2. Step1: Install nginx 1. Install nginx sudo apt-get update sudo apt-get install nginx 2. Display your ip sudo service nginx start
  • 3. Step1: Install nginx 3. Start nginx sudo service nginx start 4. Create new config nginx for your app sudo vim /etc/nginx/conf.d/sieunhac.conf
  • 4. Step1: Install nginx This is file sample config nginx upstream sieunhac { server unix:/tmp/sieunhac.sock fail_timeout=0; } server { listen 80; server_name 192.168.1.2; root /home/khanhpn/Project/sieunhac_v1/public; try_files $uri/index.html $uri @sieunhac; location @sieunhac { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; proxy_pass http://sieunhac; } error_log /var/log/nginx/sieunhac_error.log; access_log /var/log/nginx/sieunhac_access.log; error_page 500 502 503 504 /500.html;
  • 5. Step1: Install nginx 5. If you have nginx, you can remove all via this command bellow: sudo apt-get remove nginx nginx-full nginx-light nginx-naxsi nginx-common
  • 6. Step2: Install unicorn 1. Go to your app, and add gem ‘unicorn’ 2. Create new file config/unicorn.rb with content as bellow:
  • 7. Step2: Install unicorn app_name = 'sieunhac' root = "/home/khanhpn/Project/sieunhac_v1" working_directory root pid_file = "#{root}/tmp/pids/#{app_name}.pid" stderr_path "#{root}/log/#{app_name}_stderr.log" stdout_path "#{root}/log/#{app_name}_stdout.log" old_pid = pid_file + '.oldbin' pid pid_file listen "/tmp/#{app_name}.sock", backlog: 64 listen(3000, backlog: 64) if ENV['RAILS_ENV'] == 'development' worker_processes ENV['RAILS_ENV'] == "production" ? 5 : 3 preload_app true timeout 60 before_fork do |server, worker| if defined?(ActiveRecord::Base) ActiveRecord::Base.connection.disconnect! end if File.exists?(old_pid) && server.pid != old_pid begin Process.kill("QUIT", File.read(old_pid).to_i) rescue Errno::ENOENT, Errno::ESRCH
  • 8. Step2: Install unicorn 3. Start unicorn via this command bundle exec unicorn -E development -c config/unicorn.rb
  • 9. Step2: Install unicorn 4. Start unicorn via service of ubuntu Create new file vim /etc/init.d/unicorn_sieunhac
  • 10. Step2: Install unicorn # Provides: unicorn # Required-Start: $remote_fs $syslog # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Manage unicorn server # Description: Start, stop, restart unicorn server for a specific application. ### END INIT INFO set -e # Feel free to change any of the following variables for your app: TIMEOUT=${TIMEOUT-60} APP_ROOT=/home/khanhpn/Project/sieunhac_v1 PID=$APP_ROOT/tmp/pids/sieunhac.pid CMD="cd $APP_ROOT; bundle exec unicorn -D -c $APP_ROOT/config/unicorn.rb -E development" AS_USER=khanhpn set -u OLD_PIN="$PID.oldbin" sig () {
  • 11. Step2: Install unicorn 5. Start unicorn via this command sudo /etc/init.d/unicorn_sieunhac start