Skip to content

Instantly share code, notes, and snippets.

@aribeiro
Forked from mauricio/default
Created February 29, 2012 12:53

Revisions

  1. @mauricio mauricio revised this gist Feb 11, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion default
    Original file line number Diff line number Diff line change
    @@ -27,7 +27,7 @@
    proxy_pass http://shop;
    proxy_redirect off;

    proxy_set_header Host $host;
    proxy_set_header Host $host:$proxy_port;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

  2. @mauricio mauricio revised this gist Aug 29, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion default
    Original file line number Diff line number Diff line change
    @@ -19,7 +19,7 @@
    server_name localhost;

    root /home/deployer/shop/current/public;
    access_log on;
    access_log /var/log/nginx/shop_access.log;
    rewrite_log on;

    location / {
  3. @mauricio mauricio revised this gist Aug 26, 2010. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion deploy.rb
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,6 @@
    set :runner, "deployer"
    set :repository, "[email protected]:mauricio/linuxfi-loja.git"
    set :scm, :git
    set :real_revision, lambda { source.query_revision(revision) { |cmd| capture(cmd) } }
    #options necessary to make Ubuntu’s SSH happy
    ssh_options[:paranoid] = false
    default_run_options[:pty] = true
  4. @mauricio mauricio created this gist Aug 25, 2010.
    56 changes: 56 additions & 0 deletions default
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,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 on;
    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;
    }

    }
    19 changes: 19 additions & 0 deletions deploy.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    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, "[email protected]:mauricio/linuxfi-loja.git"
    set :scm, :git
    set :real_revision, lambda { source.query_revision(revision) { |cmd| capture(cmd) } }
    #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
    31 changes: 31 additions & 0 deletions nginx.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,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/*;
    }
    49 changes: 49 additions & 0 deletions unicorn
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,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
    17 changes: 17 additions & 0 deletions unicorn.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,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"