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. JS复制内容到剪贴板: 兼容IE、Firefox、Chrome、Safari所有浏览器【转】

    正 文: 现在浏览器种类也越来越多,诸如 IE.Firefox.Chrome.Safari等等,因此现在要实现一个js复制内容到剪贴板的小功能就不是一件那么容易的事了. 在FLASH 9 时代,有一个 ...

  2. 使用mysqldump迁移数据

    1. 先停止业务,使用MySQLdump的数据导出工具,将您线下原有数据库数据导出为数据文件 mysqldump -hlocalhost -uroot --default-character-set= ...

  3. oracle数据库插入优化

    通过程序要把1000万的数据插入到数据表中,刚开始每100条数据耗时50ms左右,但是越往后越慢,最慢到了十几秒的都有,真实好坑了. 于是在网上百度了一波,如何进行insert优化.倒是有了一点小小的 ...

  4. c 结构体中存在指针,指针的不同赋值方法

    #include<stdio.h>#include<stdlib.h>#include<string.h>struct parameter{ char *fd; i ...

  5. java-ConcurrentLinkedQueue 简单使用

    import java.util.concurrent.ConcurrentLinkedQueue; public class CacheTest { /** * * offer(E e) 将指定元素 ...

  6. 值提供器 AND 模型绑定器

    本章介绍了值提供器的作用,ASP MVC自带的5中值提供器.以及模型绑定器的作用,自定义模型绑定器并使用自定义的模型绑定器(类型上加上[ModelBinder(typeof(xx))]或者在全局模型绑 ...

  7. mysql数据库(二):查询(SELECT)

    一. 数据库查询—查询(SELECT) 单表查询 多表联合查询 二. 查询—单表查询 查询特定字段: select <字段1,字段2,...> from <表名>; 示例:查询 ...

  8. 如何去除pycharm中代码下的波浪线

    Pycharm中新建一个工程,如果不经过配置,在该工程下创建模块写代码,通常是有波浪线的,这样看着很不美观 如何解决这种问题,通常有两种方法 方法一:点击右下角的图标,会出现一个Highlightin ...

  9. ubuntu下搭建hadoop平台

    终于把单击模式跟伪分布式模式搭建起来了,记录于此. 1.SSH无密码验证配置 因为伪分布模式下DataNode和NameNode均是本身,所以必须配置SSH localhost的无密码验证. 第一步, ...

  10. L138

    Research indicates that lifestyles are changing fast.The essay isn't even remotely relevant to the t ...