Rails+unicorn+nginx configuration, Shell startup scripts

Source: Internet
Author: User

1. Nginx configuration file1.1, the project directory is placed in the system/var/www/
Upstream App {# Path to Unicorn SOCK file, as defined Previouslyserver unix:/var/www/app/shared/sockets/unicorn.sock Fail_ timeout=0; #server 127.0.0.1:4000 fail_timeout=0;} server {Listen 80;server_name app.example.cn;access_log/var/log/nginx/app_access.log;error_log/var/log/nginx/app_ Error.log;proxy_redirect off;root/var/www/app/public;location/{try_files $uri/index.html $uri @app;} Location @app {proxy_pass Http://app;proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;proxy_set_header Host $http _host;proxy_redirect off;} Error_page 502 503 504/500.html;client_max_body_size 4g;keepalive_timeout 10;}
2. Unicorn configuration file, Touch config/unicorn.rb2.1 Creating a Filemkdir-p shared/pids shared/sockets shared/log
App_dir = file.expand_path (".. /.. ",  __file__) shared_dir = " #{app_dir}/shared "working_directory app_dirworker_processes  2preload_app truetimeout 30listen  "#{shared_dir}/sockets/unicorn.sock",  :backlog  => 64# Loggingstderr_path  "#{shared_dir}/log/unicorn.stderr.log" stdout_path  "#{ Shared_dir}/log/unicorn.stdout.log "pid " #{shared_dir}/pids/unicorn.pid "#before_fork  do |server,  worker|#  defined? (activerecord::base)  and ActiveRecord::Base.connection.disconnect!##  old_pid =  "#{ server.config[:p Id] }.oldbin" #  unless old_pid == server.pid#     begin#      process.kill :quit, file.read (Old_pid). to_i#    rescue errno::enoent, errno::esrch#    end#   end#end# #after_fork  do |server, worker|#  defined? (activerecord::base)  and activerecord::base.establish_connection#end
3. Create a Unicorn startup script3.1 Create SH mkdir below the project directory./sh Touch server_crl.sh&& VI server_crl.sh3.2, Chomd +x./server_crl.sh
#!/bin/sh### begin init info# provides:           unicorn# Required-Start:     $all # required-stop:       $all # default-start:     2 3 4 5# default-stop:       0 1 6# short-description: starts the unicorn  app server# Description:       starts unicorn  Using start-stop-daemon### end init infoset -eusage= "Usage: $0 <start| Stop|restart|upgrade|rotate|force-stop> "# app settingsas_user=" Ubuntu "app_name=" app "APP_ROOT="/ var/www/$APP _name "env=" Production "# environment settingspath=" $PATH "cmd=" cd  $APP _root  && bundle exec unicorn -c config/unicorn.rb -E  $ENV  -d "pid=" $ App_root/shared/pids/unicorn. pid "Old_pid=" $PID. Oldbin "# make sure the app existscd  $APP _root | |  exit 1sig  ()  {  test -s  "$PID"  && kill -$1   ' cat  $PID '}oldsig  ()  {  test -s  $OLD _pid && kill  -$1  ' cat  $OLD _pid '}run  ()  {  if [  "$ (id -un)"  =  " $AS _user " ]; then    eval $1  else    su  -c  "$"  -  $AS _user  fi}case $1 in  start)      sig 0 && echo >&2  "Already running"  &&  exit 0    echo  "starting  $APP _name"     run  "$CMD"     ;;   stop)     echo  "stopping  $APP _name"     sig  Quit && exit 0    echo >&2  "Not running"      ;;   force-stop)     echo  "force stopping  $APP _name"      sig TERM && exit 0    echo >&2  " Not running "    ;;   restart|reload|upgrade)     sig USR2 && echo  " reloaded  $APP _name " && exit 0    echo >&2 " Couldn ' t reload, starting  ' $CMD '  instead '     run  ' $CMD '      ;;   rotate)     sig usr1 && echo rotated logs  OK && exit 0    echo >&2  "Couldn ' t  Rotate logs "&NBSP;&AMP;&AMP;&NBSP;EXIT&NBSP;1&NBSP;&NBSP;&NBSP;&NBSP;;;   *)     echo >&2  $USAGE     exit 1     ;; Esac


Rails+unicorn+nginx configuration, Shell startup scripts

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.