Tag Archives: unicorn

ActionDispatch::RemoteIp::IpSpoofAttackError

使用 unicorn + nginx 运行 rails 有一段时间了,之前 nginx 这样配置 ip 地址 proxy_set_header X-Real-IP $remote_addr; 发现 rails 中获取到的 ip 是 127.0.0.1 , 然后又配置 CLIENT_IP proxy_set_header CLIENT_IP $remote_addr; 这样配置之后就发现了 rails 的错误 ActionDispatch::RemoteIp::IpSpoofAttackError 原来 rails 有 ip 防欺骗,再改 ningx 配置,加入 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; … Continue reading

Posted in ruby on rails | Tagged , , , | Leave a comment

Unicorn 无缝重启

无缝重启: 重启过程中不能中断服务,因为网站都是需要7×24提供服务的,不能每次更新代码网站都有一断时间 无法访问,虽然中间可能只有不到1分钟的时间。 不管任何服务进程要实现无缝重启,大概都得按照先开新的进程接,然后优雅的结束老的进程, 优雅的结束老的进程意思是老的进程要处理完当前的请求之后才能结束。 Unicorn 无缝重启简单 5 步搞定:(官方的文档) 给 Unicorn 主进程发送 USR2 信号 kill -USR2 pid 确定当前新的主进程已经完成启动,如果使用 pid 文件,那么会生成一个 .oldbin 的文件存放老的主进程 pid。 现在呢,会有 2 个主进程和双份的 worker 进程,类似下面的进程树: unicorn master (old) \_ unicorn worker[0] \_ unicorn worker[1] \_ unicorn worker[2] … Continue reading

Posted in ruby on rails | Tagged | Leave a comment

unicorn 部署 Ruby on Rails 开机自启动

最近把 s.yanghao.org 从 php + python 转型到 Rails 框架, 第一次使用 Rails 遇到的麻烦真不少,最麻烦的还真得算部署, 如果不计较安全问题,统统使用 root 帐号操作,这些问题就不是什么问题, 为了安全,我们做以下限定: 不能使用 root 帐号运行 unicorn 进程 运行 unicorn 的帐号不能有 sudo 权限 为了使服务器能运行不同 ruby 版本,应使用 rvm 用户模式安装 ruby 这些为我们带来的问题: 开机需要自动运行 unicorn 重新部署之后需要重启 unicorn 开机自动运行 unicorn 可以使用 … Continue reading

Posted in ruby on rails | Tagged | Leave a comment