知识屋:更实用的电脑技术知识网站
所在位置:首页 > 操作系统 > linux

unicorn+nginx+centos部署及服务器配置

发布时间:2014-09-05 13:26:52作者:知识屋

要将dashboard部署到服务器上,我们还需要一个服务器用于运行ruby程序,这里用到的是unicorn。

Unicorn 配置

这个世界让人联想起部署python时用到的gunicorn,下面这些来自于网上。

Unicorn

为 Rack 应用程序设计的 HTTP server是一个利用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 6working_directory root_pathtimeout 30# 侦听listen 8080, tcp_nopush: falselisten socket_file, backlog: 1024pid pid_filestderr_path err_logstdout_path log_filepreload_app truebefore_exec do |server|  ENV['BUNDLE_GEMFILE'] = root_path + '/Gemfile'endbefore_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 bootupUNICORN=unicornCONFIG_FILE=/home/www/iot-dashboard/config/unicorn.rbAPP_HOME=/home/www/iot-dashboardcase "$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:
(免责声明:文章内容如涉及作品内容、版权和其它问题,请及时与我们联系,我们将在第一时间删除内容,文章内容仅供参考)
收藏
  • 人气文章
  • 最新文章
  • 下载排行榜
  • 热门排行榜