public
Last active

  • Download Gist
default
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
# 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;
break;
}
 
}
deploy.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
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, "git@github.com:mauricio/linuxfi-loja.git"
set :scm, :git
#options necessary to make Ubuntu’s SSH happy
ssh_options[:paranoid] = false
default_run_options[:pty] = true
 
role :app, "184.106.215.175"
role :web, "184.106.215.175"
role :db, "184.106.215.175", :primary => true
nginx.conf
Nginx
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
user deployer staff;
worker_processes 4;
 
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
 
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/*;
}
unicorn
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
#! /bin/sh
 
### BEGIN INIT INFO
# 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
### END INIT INFO
 
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/unicorn_rails
DAEMON_OPTS="-c /home/deployer/shop/current/unicorn.rb -E production -D"
NAME=unicorn_rails
DESC=unicorn_rails
PID=/home/deployer/shop/shared/pids/unicorn.pid
 
case "$1" in
start)
echo -n "Starting $DESC: "
$DAEMON $DAEMON_OPTS
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
kill -QUIT `cat $PID`
echo "$NAME."
;;
restart)
echo -n "Restarting $DESC: "
kill -QUIT `cat $PID`
sleep 1
$DAEMON $DAEMON_OPTS
echo "$NAME."
;;
reload)
echo -n "Reloading $DESC configuration: "
kill -HUP `cat $PID`
echo "$NAME."
;;
*)
echo "Usage: $NAME {start|stop|restart|reload}" >&2
exit 1
;;
esac
 
exit 0
unicorn.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
# See http://unicorn.bogomips.org/Unicorn/Configurator.html 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/unicorn.pid"
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:
http://stackoverflow.com/questions/6402278/serving-precompiled-assets-with-nginx/9354946#9354946

so that your assets serve

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.