unicorn+nginx+centos導入およびサーバ構成


dashboardをサーバに配備するには、rubyプログラムを実行するためのサーバが必要です.ここではunicornを使用します.
Unicornは、pythonを導入する際に使用されるgunicornを連想させる世界を構成しています.以下はネット上から来ています.
Unicorn
  • Rackアプリケーション用に設計されたHTTPサーバ
  • はUnixの高度な特性を利用して開発された
  • である.
  • は、低遅延、高帯域幅の接続を備えるカスタマーサービス
  • である.
    テキストhttp://www.phodal.com/blog/unicorn-nginx-ruby-centos-deploy-configure/
    Unicornのインストール
    gem install unicorn

    unicornの構成
    # -*- encoding: utf-8 -*-
    
    
    root_path = File.expand_path '../', File.dirname(__FILE__)
    #   
    log_file = root_path + '/log/unicorn.log'
    err_log  = root_path + '/log/unicorn_error.log'
    #     
    pid_file = '/tmp/unicorn_padrino.pid'
    old_pid = pid_file + '.oldbin'
    #   
    socket_file = '/tmp/unicorn_padrino.sock'
    
    
    worker_processes 6
    working_directory root_path
    timeout 30
    #   
    listen 8080, tcp_nopush: false
    listen socket_file, backlog: 1024
    
    
    pid pid_file
    stderr_path err_log
    stdout_path log_file
    
    
    preload_app true
    
    
    before_exec do |server|
      ENV['BUNDLE_GEMFILE'] = root_path + '/Gemfile'
    end
    
    
    before_fork do |server, worker|
      if File.exists?(old_pid) && server.pid != old_pid
        begin
          Process.kill('QUIT', File.read(old_pid).to_i)
        rescue Errno::ENOENT, Errno::ESRCH
          puts "Send 'QUIT' signal to unicorn error!"
        end
      end
      end

    nginxを構成するために使用されるエージェントは、前に学んだエージェントです.
    upstream app_server {
        server unix:/tmp/unicorn_padrino.sock fail_timeout=0;
    }
    
    
    server {
        listen   80;
        charset  utf-8;
        server_name  dashboard.phodal.com;
        keepalive_timeout 5;
        root        /home/www/iot-dashboard;
        access_log  /home/www/iot-dashboard/log/nginx_access.log;
        error_log   /home/www/iot-dashboard/log/nginx_error.log;
        rewrite_log on;
        location ~* ^/(images|javascripts|stylesheets|img)/  {
            access_log    off;
            log_not_found off;
            expires       max;
            break;
        }
        location / {
            proxy_set_header Host               $host;
            proxy_set_header X-Forwarded-Host   $host;
            proxy_set_header X-Forwarded-Server $host;
            proxy_set_header X-Real-IP          $remote_addr;
            proxy_set_header X-Forward-For      $proxy_add_x_forwarded_for;
            proxy_buffering  on;
            proxy_redirect   off;
            if (!-f $request_filename) {
                proxy_pass http://app_server;
                break;
            } 
        }
    
    
    }

    スクリプトの作成
    この部分はネット上から来ています
    #!/bin/sh
    # rvm wrapper ruby-1.9.3-p194 bootup
    UNICORN=unicorn
    CONFIG_FILE=/home/www/iot-dashboard/config/unicorn.rb
    APP_HOME=/home/www/iot-dashboard
    
    
    case "$1" in
          start)
              $UNICORN -c $CONFIG_FILE -E production -D
                ;;
          stop)
              kill -QUIT `cat /tmp/unicorn_padrino.pid`
                ;;
          restart|force-reload)
                kill -USR2 `cat /tmp/unicorn_padrino.pid`
                  ;;
          *)
               echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
                  exit 3
                     ;;
        esac
    
    
    :