Skip to content
Create a gist now

Instantly share code, notes, and snippets.

# as we’re going to use Unicorn as the application server
# we’re not going to use common sockets
# but Unix sockets for faster communication
upstream shop {
# fail_timeout=0 means we always retry an upstream even if it failed
# to return a good HTTP response (in case the Unicorn master nukes a
# single worker for timing out).
# for UNIX domain socket setups:
server unix:/tmp/shop.socket fail_timeout=0;
server {
# if you're running multiple servers, instead of "default" you should
# put your main domain name here
listen 80 default;
# you could put a list of other domain names this application answers
server_name localhost;
root /home/deployer/shop/current/public;
access_log /var/log/nginx/shop_access.log;
rewrite_log on;
location / {
#all requests are sent to the UNIX socket
proxy_pass http://shop;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
# if the request is for a static resource, nginx should serve it directly
# and add a far future expires header to it, making the browser
# cache the resource and navigate faster over the website
location ~ ^/(images|javascripts|stylesheets|system)/ {
root /home/deployer/shop/current/public;
expires max;
set :use_sudo, false
#tell git to clone only the latest revision and not the whole repository
set :git_shallow_clone, 1
set :keep_releases, 5
set :application, "shop"
set :user, "deployer"
set :password, "asdfg"
set :deploy_to, "/home/deployer/shop"
set :runner, "deployer"
set :repository, ""
set :scm, :git
#options necessary to make Ubuntu’s SSH happy
ssh_options[:paranoid] = false
default_run_options[:pty] = true
role :app, ""
role :web, ""
role :db, "", :primary => true
user deployer staff;
worker_processes 4;
error_log /var/log/nginx/error.log;
pid /var/run/;
events {
worker_connections 1024;
accept_mutex on;
http {
include /etc/nginx/mime.types;
access_log /var/log/nginx/access.log;
sendfile on;
tcp_nopush on; # off may be better for *some* Comet/long-poll stuff
tcp_nodelay off; # on may be better for some Comet/long-poll stuff
gzip on;
gzip_http_version 1.0;
gzip_proxied any;
gzip_min_length 500;
gzip_disable "MSIE [1-6]\.";
gzip_types text/plain text/html text/xml text/css text/comma-separated-values text/javascript application/x-javascript application/atom+xml;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
#! /bin/sh
# Provides: unicorn
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the unicorn web server
# Description: starts unicorn
DAEMON_OPTS="-c /home/deployer/shop/current/unicorn.rb -E production -D"
case "$1" in
echo -n "Starting $DESC: "
echo "$NAME."
echo -n "Stopping $DESC: "
kill -QUIT `cat $PID`
echo "$NAME."
echo -n "Restarting $DESC: "
kill -QUIT `cat $PID`
sleep 1
echo "$NAME."
echo -n "Reloading $DESC configuration: "
kill -HUP `cat $PID`
echo "$NAME."
echo "Usage: $NAME {start|stop|restart|reload}" >&2
exit 1
exit 0
# See for complete
# documentation.
worker_processes 4
# Help ensure your application will always spawn in the symlinked
# "current" directory that Capistrano sets up.
working_directory "/home/deployer/shop/current"
# listen on both a Unix domain socket and a TCP port,
# we use a shorter backlog for quicker failover when busy
listen "/tmp/shop.socket", :backlog => 64
# nuke workers after 30 seconds instead of 60 seconds (the default)
timeout 30
# feel free to point this anywhere accessible on the filesystem
user 'deployer', 'staff'
shared_path =/home/deployer/shop/shared”
pid "#{shared_path}/pids/"
stderr_path "#{shared_path}/log/unicorn.stderr.log"
stdout_path "#{shared_path}/log/unicorn.stdout.log"

for Rails 3.1 apps, you'll need to update your configs with the comment that Ben W makes here:

so that your assets serve

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.