看到 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;
}
}