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. vector push_back数量大的时候变慢

    才用15000个数据  push_back耗时就好几秒, 解决方法是 先resize 15000, 然后再 for (int i = 0; i < 15000; i++) { Data data ...

  2. org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [bean.xml]: Invocation of init method failed; nested exception is

    在复制xml文件进行修改的时候,我经常将不小心对原文件进行修改,而导致创建bean出错.报错如下所示: Exception sending context initialized event to l ...

  3. SSL HTTPS 生成证书

    SSL HTTPS 一.生成服务器私钥.公钥 $ openssl genrsa -out server.key 2048 $ openssl rsa -in server.key -pubout -o ...

  4. lftp使用

    lftp -c 'pget -n 5 ftp://user:password@ftpserver/test.txt'  5 线程数 安装: yum install lftp -y使用语法:lftp - ...

  5. Python主流框架

    15个最受欢迎的Python开源框架.这些框架包括事件I/O,OLAP,Web开发,高性能网络通信,测试,爬虫等. Django: Python Web应用开发框架Django 应该是最出名的Pyth ...

  6. Oracle Package

    (转自:http://blog.csdn.net/bbliutao/article/details/9016947) 一.概述包可将一些有联系的对象放在其内部.任何能在块定义部分出现的对象都可以在包中 ...

  7. 【lightoj-1039】A Toy Company(BFS)

    The toy company "Babies Toys" has hired you to help develop educational toys. The current ...

  8. C#学习历程(二)[基础知识]

    c#中类型的转换 1.Convert.ToInt32(string s) 这个方法的返回值是int类型,要用int类型的变量接收 如: string strNum=Console.ReadLine() ...

  9. (转)程序员应该知道的10个eclipse调试技巧

    调试不仅可以查找到应用程序缺陷所在,还可以解决缺陷.对于Java程序员来说,他们不仅要学会如何在Eclipse里面开发像样的程序,更需要学会如何调试程序.本文介绍了Java程序员必知的10个调试技巧, ...

  10. Activity传递参数——传递复杂数据(Bunble包)

    一.新建一个空的工程 二.在主界面中添加一个按钮 三.新建一个空的activity,并命名为TheAty 四.修改MainActivity.java中的onCreate函数 protected voi ...