unicorn是目前在ror上比较流行的应用服务器,配合nginx用来直接部署rails程序,下面这种方式应该是共享socket,不断fork子进程,有点类似php-fpm的模式

安装unicorn

gem install unicorn
或者在你的项目里修改gemfile
gem 'unicorn'

流程描述

给rails程序配置unicorn的启动脚本
在外部unicorn_rails /xxxx/yyyy/zzzz/unicorn.rb启动rails程序
nginx配置下,连接到后端的ror程序

下面是详细的脚本部分

比如我们有个名字为hello的ror项目

在hello/config下建立unicorn.rb

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_hello.pid'
old_pid = pid_file + '.oldbin' socket_file = '/tmp/unicorn_hello.sock' worker_processes
working_directory root_path
listen socket_file, backlog:
timeout pid pid_file
stderr_path err_log
stdout_path log_file preload_app true before_exec do |server|
ENV['BUNDLE_GEMFILE'] = root_path + '/Gemfile' defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
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 defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
end

在hello项目的外面,建立start_hello.sh

#!/bin/sh

UNICORN=unicorn_rails
#这里需要全路径
CONFIG_FILE=/home/mmc/Projects/ruby/hello/config/unicorn.rb case "$1" in
start)
#$UNICORN -c $CONFIG_FILE -E production -D
$UNICORN -c $CONFIG_FILE -D
;;
stop)
kill -QUIT `cat /tmp/unicorn_hello.pid`
;;
restart|force-reload)
kill -USR2 `cat /tmp/unicorn_hello.pid`
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&
exit
;;
esac

执行sh start_hello.sh start

最后配置nginx

upstream unicorn {
server unix:/tmp/unicorn_hello.sock fail_timeout=;
} server {
listen default deferred;
root /home/mmc/Projects/ruby/hello/; location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
} try_files $uri/index.html $uri @unicorn;
location @unicorn {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://unicorn;
} error_page /.html;
client_max_body_size 4G;
keepalive_timeout ;
}

启动sudo invoke-rc.d nginx restart

http://127.0.0.1应该能看到ror的页面了

ror配置unicorn部署的更多相关文章

  1. 分布式文件系统 - FastDFS 在 CentOS 下配置安装部署

    少啰嗦,直接装 看过上一篇分布式文件系统 - FastDFS 简单了解一下的朋友应该知道,本次安装是使用目前余庆老师开源的最新 V5.05 版本,是余庆老师放在 Github 上的,和目前你能在网络上 ...

  2. 阿里云服务器Linux CentOS安装配置(五)jetty配置、部署

    阿里云服务器Linux CentOS安装配置(五)jetty配置.部署 1.官网下载jetty:wget http://repo1.maven.org/maven2/org/eclipse/jetty ...

  3. SSD Cloud Hosting - Linode的配置和部署,搭建Java环境

    0.发牢骚 前一个月在淘宝购买了个Jsp空间,挺便宜的,才38元/年.部署了程序,然后ALIMAMA验证网站,一直提示验证失败.最后找卖家,他说可能是因为空间太慢,照他的推荐换了最好的空间,138元/ ...

  4. jetty之安装,配置,部署,运行

    上篇文章中详解了关于什么是jetty,后续文章主要是介绍jetty的使用.本章介绍jetty环境的配置及部署war包. 1. 安装 1. 先下载一个jetty的压缩包,下载地址:http://www. ...

  5. JBOSS EAP6.2.0的下载安装、环境变量配置以及部署

    JBOSS EAP6.2.0的下载安装.环境变量配置以及部署 JBoss是纯Java的EJB(企业JavaBean)server. 第一步:下载安装 1.进入官网http://www.jboss.or ...

  6. jrebel配置热部署参数

    jrebel配置热部署参数: -noverify -agentpath:D:/jrebel/lib/jrebel64.dll -Drebel.dirs=E:/workspace/item/src/ma ...

  7. Jenkins-在windows上配置自动化部署(Jenkins+Gitblit)

    Jenkins-在windows上配置自动化部署(Jenkins+Gitblit) 1. 安装好 Jenkins(注:安装目录需没有空格,否则安装gitlab hook 插件时会报错,安装在c盘跟目录 ...

  8. Intellij IDEA 4种配置热部署的方法【转】【补】

    热加载 热加载可以使代码修改后无须重启服务器,就可以加载更改的代码.(其实分java和非java代码,本处可以让java代码立即生效且不重启服务) 第1种:修改服务器配置,使得IDEA窗口失去焦点时, ...

  9. 【VMware虚拟化解决方案】配置和部署VMware ESXi5.5

    [VMware虚拟化解决方案]配置和部署VMware ESXi5.5 时间 2014-04-08 10:31:52  让"云"无处不在的博客原文  http://mabofeng. ...

随机推荐

  1. flume-ng源码阅读memory-channel(原创)

    org.apache.flume.channel.MemoryChannel类是Flume-NG的memory-channel. private LinkedBlockingDeque<Even ...

  2. NumPy矩阵库

    NumPy - 矩阵库 NumPy 包包含一个 Matrix库numpy.matlib.此模块的函数返回矩阵而不是返回ndarray对象. matlib.empty() matlib.empty()函 ...

  3. java模拟http的get和post请求

    如题,使用Java模拟GET和POST请求.使用GET可以实现网页抓取,使用POST可以实现对某些网站登录的暴力破解.不过仅是练习,实际意义不大. import java.io.IOException ...

  4. CSS 技巧总结

    CSS 技巧和经验列表 1. 如何清除图片下方出现的几像素的空白 方法一: img{display:block;} 方法二: img{vertical-align:top;} 除了top值,还可以设置 ...

  5. InflateException:Bin file line #19:Error inflating class MyTextView

    InflateException:Bin file line #19:Error inflating class MyTextView 一.错误简介 为了实现TextView的跑马灯效果,我自己写了一 ...

  6. 一台电脑上同时使用两个github账户

    需求:公司有github账号,自己有github账号,想在Git上同时使用,两者互不干扰. 思路:管理两个SHH key. 解决办法: 一.生成两个SSH key 为了举例方便,这里使用“one”和“ ...

  7. IOS-CoreLocation

    一.简介 在移动互联网时代,移动app能解决用户的很多生活琐事,比如 导航:去任意陌生的地方 周边:找餐馆.找酒店.找银行.找电影院   在上述应用中,都用到了地图和定位功能,在iOS开发中,要想加入 ...

  8. New Concept English three (43)

    30 54 Insurance companies are normally willing to insure anything. Insuring public or private proper ...

  9. PhotoShop脚本指南

    Photoshop脚本语言 Photoshop支持三种脚本语言:AppleScript,VBScript,JavaScript.其中AppleScript为苹果系统,VBScript为Windows操 ...

  10. MPLS基础一

    多协议标签交换(MPLS) 是一种用于快速数据包交换和路由的体系,具有管理各种不同形式通信流的机制. 内容:RID     /     MTU     /      认证    /     TTL   ...