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. ViewPager实现图片的轮播

    在app中图片的轮播显示可以说是非常常见的实现效果了,其实现原理不过是利用ViewPager,然后利用handler每隔一定的时间将ViewPager的currentItem设置为当前item的pos ...

  2. Android -- UI布局管理,相对布局,线性布局,表格布局,绝对布局,帧布局

    1. 相对布局 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmln ...

  3. java手动分页处理

    经常我们在操作数据库的时候都会用到分页,而且很多框架也提供了分页功能,像PageHelper. 但是在有些项目中,需要将数据查询出来进行手动分页,那么原理是什么呢? 其实很简单,首先需要知道数据总量, ...

  4. 布置weblogic10 64位系统

    1.下载64位JDK并安装 2.java -D64 -jar wls1036_generic.jar(注意下载下来的wls1036_generic.jar文件不要解压,用此命令解压) 3.点击下一步, ...

  5. lightoj1370欧拉函数/素数筛

    这题有两种解法,1是根据欧拉函数性质:素数的欧拉函数值=素数-1(可根据欧拉定义看出)欧拉函数定义:小于x且与x互质的数的个数 #include<map> #include<set& ...

  6. nt":false,"tarball":"http://registry.npm.taobao.org/babel-preset-stag

    npm ERR! Unexpected end of input at 1:12777 npm ERR! nt":false,"tarball":"http:/ ...

  7. 【scala】迭代器

    如何访问集合呢?我们首先想到的是使用for循环来访问,还有一种方法是通过迭代器来访问. 在Scala中,迭代器(Iterator)不是一个集合,但是,提供了访问集合的一种方法. 迭代器包含两个基本的操 ...

  8. hdu1845

    题解: 只要输出n/2即可 代码: #include<cstdio> #include<cmath> #include<cstring> #include<a ...

  9. Spring 依赖注入(一、注入方式)

    Spring是一个依赖注入(控制反转)的框架,那么依赖注入(标控制反转)表现在那些地方了? 即:一个类中的属性(其他对象)不再需要手动new或者通过工厂方法进行创建,而是Spring容器在属性被使用的 ...

  10. LeetCode OJ:Linked List Cycle II(循环链表II)

    Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Note ...