新手问题 有关用 Puma 报 504 超时的问题

cassiuschen · 2013年11月03日 · 最后由 jasl 回复于 2013年11月04日 · 3769 次阅读

看到 Ruby-China 换成 Puma 之后看了看发现内存占用的确缩小了很多,于是今天一直再试水 Puma……但是一直没有成功配置……用端口访问一点问题没有但是用 sock 之后运行puma -C config/puma.rb然后nginx如下配置总是报504超时的错误……莫非是文件权限的问题?

以及为啥运行cap deploy它总是提示说要写类似cap production deploy这样的呢?

贴出现在的情况:

config/deploy.rb

# coding: utf-8
require "bundler/capistrano"

require "rvm/capistrano"
require 'puma/capistrano'

default_run_options[:pty] = true

#========================
#CONFIG
#========================
set :application, "Mr.Course"
set :scm, :git
set :repository, "git://github.com/cassiuschen/mr.course.git"
set :branch, "master"
set :ssh_options, { :forward_agent => true }
set :stage, :production
set :user, "deploy"
set :use_sudo, false
set :runner, "deploy"
set :deploy_to, "/var/mirrors/mr.course"
set :app_server, :puma
set :domain, "mrcourse.bdfzer.com"
#========================
#ROLES
#========================
role :app, domain
role :web, domain
role :db, domain, :primary => true

#========================
#CUSTOM
#========================
namespace :puma do
  desc "Start Puma"
  task :start, :except => { :no_release => true } do
    run "sudo /etc/init.d/puma start #{application}"
  end
  after "deploy:start", "puma:start"

  desc "Stop Puma"
  task :stop, :except => { :no_release => true } do
    run "sudo /etc/init.d/puma stop #{application}"
  end
  after "deploy:stop", "puma:stop"

  desc "Restart Puma"
  task :restart, roles: :app do
    run "sudo /etc/init.d/puma restart #{application}"
  end
  after "deploy:restart", "puma:restart"

  desc "create a shared tmp dir for puma state files"
  task :after_symlink, roles: :app do
    run "sudo rm -rf #{release_path}/tmp"
    run "ln -s #{shared_path}/tmp #{release_path}/tmp"
  end
  after "deploy:create_symlink", "puma:after_symlink"
end

task :compile_assets, :roles => :web do
  run "cd #{deploy_to}/current/; RAILS_ENV=production bundle exec rake assets:precompile"
  run "cd #{deploy_to}/current/; RAILS_ENV=production bundle exec rake assets:cdn"
end

config/puma.rb

rails_env = ENV['RAILS_ENV'] || 'development'

APP_ROOT = '/var/mirrors/mr.course'

pidfile "#{APP_ROOT}/tmp/pids/puma.pid"
state_path "#{APP_ROOT}/tmp/pids/puma.state"

bind  "unix://#{APP_ROOT}/tmp/socks/puma.sock"

daemonize true
workers 4
threads 4,4

activate_control_app
preload_app!

/etc/nginx/conf.d/app.conf

upstream mrcourse {
  server unix:///var/mirrors/mrcourse/tmp/socks/puma.sock;
}

server {
  listen 80;
  server_name mrcourse.bdfzer.com;

  keepalive_timeout 5;

  root /var/mirrors/mrcourse/public;
  access_log /var/mirrors/mrcourse/log/nginx.access.log;
  error_log /var/mirrors/mrcourse/log/nginx.error.log info;

  if (-f $document_root/maintenance.html) {
    rewrite  ^(.*)$  /maintenance.html last;
    break;
  }

  location / {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;

    if (-f $request_filename) {
      break;
    }

    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://mrcourse;
      break;
    }
  }

  location ~* \.(ico|css|gif|jpe?g|png|js)(\?[0-9]+)?$ {
     expires max;
     break;
  }

  location = /500.html {
    root /var/mirrors/mrcourse/current/public;
  }
}

你用的是 capistrano v3 吧,v3 支持多种环境的部署,默认提供了 production 和 staging 两个环境,所以执行命令的时候需要之名部署的的目标环境。

#1 楼 @chunlea 那为啥输入cap production deploy也不行呢?

#2 楼 @cassiuschen 额,没用过 puma,有没有看看 log 是不是由错误信息?建议核对下你的 nginx 配置文件,参考 https://github.com/puma/puma/blob/master/docs/nginx.md 还有,

用端口访问一点问题没有

是指你用 puma 跑,然后通过端口访问而不走 nginx?

#2 楼 @cassiuschen 因为没有 production 环境的 deploy 脚本哇 看文档先初始化一下 3 跟 2 比改动比较大,2 的 recipe 基本都不能用了

#4 楼 @jasl 改动是很大,但是文档很多都是 2 的,怎么办?

#4 楼 @jasl 懂得了!十分感谢~

#5 楼 @zgm 文档,主要是 recipe 要重写,这个工作量有点大,但部署脚本迁移起来还不算困难,2 时代有个 multi-deploy 的插件,3 不过是强制而已

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