Nginx RVM+Puma+Nginx 环境

mimosa · 2012年07月16日 · 最后由 xworm 回复于 2014年05月09日 · 9915 次阅读

生成命令,/home/howl/.rvm/bin/bootup_puma

rvm wrapper ruby-1.9.3-p125-perf bootup puma

创建 Puma 的配置文件,/etc/puma/puma.rb

bind 'unix:///tmp/puma.sock'
pidfile '/tmp/puma.pid'
rackup '/home/howl/one/config.ru'

创建服务,/etc/init.d/puma

#!/bin/sh
### BEGIN INIT INFO
# Provides:          puma
# Required-Start:    $local_fs $remote_fs
# Required-Stop:     $local_fs $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      S 0 1 6
# Short-Description: puma initscript
# Description:       puma
### END INIT INFO

# Original author: Forrest Robertson

# Do NOT "set -e"

DAEMON=/home/howl/.rvm/bin/bootup_puma # /home/howl/.rvm/gems/ruby-1.9.3-p125-perf/bin/puma
SCRIPT_NAME=/etc/init.d/puma
CONFIG_FILE=/etc/puma/puma.rb
APP_PATH=/home/howl/one
PID=/tmp/puma.pid

# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0

case "$1" in
  start)
        cd $APP_PATH && $DAEMON -C $CONFIG_FILE > $APP_PATH/log/puma.log 2>&1  &
        ;;
  stop)
        kill -9 `cat $PID`
        ;;
  restart)
        kill -SIGUSR2 `cat $PID`
        ;;
  *)
        echo "Usage: $SCRIPT_NAME {start|stop|restart}" >&2
        exit 3
        ;;
esac

修改 nginx.conf:

upstream howl_cluster {
  # server unix:/tmp/thin.howl.sock;
  server unix://tmp/puma.sock fail_timeout=0;
}
server {
    listen 80;
server_name imgcdn.shareday.com;
root /home/howl/taobao;
}

server {
    listen 80;
    server_name shareday.com www.shareday.com shfeiming.com;
    root /home/howl/www/public;
    access_log /home/howl/nginx/access.log;
    error_log  /home/howl/nginx/error.log;
    location / {
      proxy_redirect    off;
      proxy_set_header  Host             $http_host;
      proxy_set_header  X-Real-IP        $remote_addr;
      proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;

      if (-f $request_filename/index.html) {
        rewrite (.*) $1/index.html break;
      }

      if (-f $request_filename.html) {
        rewrite (.*) $1.html break;
      }

      if (!-f $request_filename) {
        proxy_pass http://howl_cluster;
        break;
      }
    }
}

和 thin 不同,在 puma 的重启前,必须先停掉 nginx,否则 puma.sock 被占用。

Address already in use - /tmp/puma.sock (Errno::EADDRINUSE)

原因在于,进程被杀掉后,puma.sock 依旧存在?!

这个有啥不同之处?

多谢分享。

遇到

Errno::EIO at / 
Input/output error - <STDOUT>

问题,待解决~

puma 文档中说,puma 的实现不完整,需要在关闭或重启时自己处理如 redis 连接之类的东西,不知道 lz 怎么做的?

#4 楼 @suupic 我昨天刚开始接触,还不熟,我们可以一起研究,分享下。

puma 重启需要停掉 nginx? 不需要啊。。。

需要 登录 后方可回复, 如果你还没有账号请 注册新账号