ror配置unicorn部署
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部署的更多相关文章
- 分布式文件系统 - FastDFS 在 CentOS 下配置安装部署
少啰嗦,直接装 看过上一篇分布式文件系统 - FastDFS 简单了解一下的朋友应该知道,本次安装是使用目前余庆老师开源的最新 V5.05 版本,是余庆老师放在 Github 上的,和目前你能在网络上 ...
- 阿里云服务器Linux CentOS安装配置(五)jetty配置、部署
阿里云服务器Linux CentOS安装配置(五)jetty配置.部署 1.官网下载jetty:wget http://repo1.maven.org/maven2/org/eclipse/jetty ...
- SSD Cloud Hosting - Linode的配置和部署,搭建Java环境
0.发牢骚 前一个月在淘宝购买了个Jsp空间,挺便宜的,才38元/年.部署了程序,然后ALIMAMA验证网站,一直提示验证失败.最后找卖家,他说可能是因为空间太慢,照他的推荐换了最好的空间,138元/ ...
- jetty之安装,配置,部署,运行
上篇文章中详解了关于什么是jetty,后续文章主要是介绍jetty的使用.本章介绍jetty环境的配置及部署war包. 1. 安装 1. 先下载一个jetty的压缩包,下载地址:http://www. ...
- JBOSS EAP6.2.0的下载安装、环境变量配置以及部署
JBOSS EAP6.2.0的下载安装.环境变量配置以及部署 JBoss是纯Java的EJB(企业JavaBean)server. 第一步:下载安装 1.进入官网http://www.jboss.or ...
- jrebel配置热部署参数
jrebel配置热部署参数: -noverify -agentpath:D:/jrebel/lib/jrebel64.dll -Drebel.dirs=E:/workspace/item/src/ma ...
- Jenkins-在windows上配置自动化部署(Jenkins+Gitblit)
Jenkins-在windows上配置自动化部署(Jenkins+Gitblit) 1. 安装好 Jenkins(注:安装目录需没有空格,否则安装gitlab hook 插件时会报错,安装在c盘跟目录 ...
- Intellij IDEA 4种配置热部署的方法【转】【补】
热加载 热加载可以使代码修改后无须重启服务器,就可以加载更改的代码.(其实分java和非java代码,本处可以让java代码立即生效且不重启服务) 第1种:修改服务器配置,使得IDEA窗口失去焦点时, ...
- 【VMware虚拟化解决方案】配置和部署VMware ESXi5.5
[VMware虚拟化解决方案]配置和部署VMware ESXi5.5 时间 2014-04-08 10:31:52 让"云"无处不在的博客原文 http://mabofeng. ...
随机推荐
- 利用$http获取在服务器的json数据
以下是存储在web服务器上的 JSON 文件: http://www.runoob.com/try/angularjs/data/Customers_JSON.php { "records& ...
- HTML5标签学习
<abbr> 表示一个缩写形式,比如 "Inc."."etc.".通过对缩写词语进行标记,您就能够为浏览器.拼写检查程序.翻译系统以及搜索引擎分度器 ...
- selenium学习笔记(智能等待)
博主在尝试对百度首页用selenium完成自动登录的功能 反复多次尝试元素定位方法也未写错.最后发现问题原因: 脚本运行速度快于页面加载速度 如百度首页登录例子.脚本已经开始寻找登录弹窗 但是页面仍在 ...
- 四十五 Python分布式爬虫打造搜索引擎Scrapy精讲—elasticsearch(搜索引擎)的bool组合查询
bool查询说明 filter:[],字段的过滤,不参与打分must:[],如果有多个查询,都必须满足[并且]should:[],如果有多个查询,满足一个或者多个都匹配[或者]must_not:[], ...
- 百度之星2017初赛A-1006-度度熊的01世界
度度熊的01世界 Accepts: 967 Submissions: 3064 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/3 ...
- flask 项目 部署服务器,package安装问题(无外网链接)
1.安装所需的环境/包 1) 在一台开发机器(有网络,编译成功)安装package: pipreqs 语法: pipreqs <项目路径> 将项目所使用的所有包目录将会导出至目录:requ ...
- 封装hibernate中session(静态单例模式)
因为每次用增删改查时都需要用到session,直接做一个类,需要的时候只需要调用即可 import org.hibernate.Session; import org.hibernate.Sessio ...
- Ceph与OpenStack整合(仅为云主机提供云盘功能)
1. Ceph与OpenStack整合(仅为云主机提供云盘功能) 创建: linhaifeng,最新修改: 大约1分钟以前 ceph ceph osd pool create volumes 128 ...
- Android中Application是什么?
Application是什么? Application和Activity,Service一样,是android框架的一个系统组件,当android程序启动时系统会创建一个 application对象, ...
- 遍历输出所有子视图(View)
传入一个View,可以获取传入视图的所有子视图,写入桌面,可以在火狐浏览器下查看 /** * 程序获得了焦点就会自动调用这个方法(只要程序获得了焦点,所有控件才能接收触摸事件) */ - (void) ...