ruby-on-rails – cache:生产中nginx独角兽的[GET /]错过
作者:互联网
我正在获取缓存:我的Rails 3.2应用程序的[GET /] miss错误消息.
我使用nginx作为unicorn服务器的代理,我使用capistrano进行部署.当我启动服务器时,我会遇到很多像上面那样的重复错误. Capistrano肯定会在部署期间预编译资产.我在下面包含配置文件(抱歉是详细的).
找出错误的任何想法或至少暗示?
application.rb中
config.assets.enabled = true
production.rb
# Disable Rails's static asset server
# (Apache or nginx SHOULD already do this BUT THEY DON'T)
config.serve_static_assets = true
# Don't fallback to assets pipeline if a precompiled asset is missed
# If I disable this I don't get assets served at all
config.assets.compile = true
deploy.rb
require 'bundler/capistrano'
set :application, "network"
set :rails_env, "production"
set :deploy_to, "/var/www/#{application}"
set :repository, "/var/repo/#{application}.git".
set :branch, "master"
set :use_sudo, false
set :user, "root"
set :unicorn_conf, "#{deploy_to}/current/config/unicorn.rb"
set :unicorn_pid, "#{deploy_to}/shared/pids/unicorn.pid"
set :bundle_roles, [:app]
set :normalize_asset_timestamps, false
set :scm, :git
server "mydomain.ru", :app, :web, :db, :primary => true
namespace :deploy do
task :restart do
run "if [ -f #{unicorn_pid} ] && [ -e /proc/$(cat #{unicorn_pid}) ]; then kill -USR2 `cat #{unicorn_pid}`; else cd #{deploy_to}/current && bundle exec unicorn -c #{unicorn_conf} -E #{rails_env} -D; fi"
end
task :start do
run "cd #{deploy_to}/current && bundle exec unicorn -c #{unicorn_conf} -E #{rails_env} -D"
end
task :stop do
run "if [ -f #{unicorn_pid} ] && [ -e /proc/$(cat #{unicorn_pid}) ]; then kill -QUIT `cat #{unicorn_pid}`; fi"
end
end
unicorn.rb
DEPLOY_TO = "/var/www/network"
RAILS_ROOT = "#{DEPLOY_TO}/current"
PID_FILE = "#{DEPLOY_TO}/shared/pids/unicorn.pid"
SOCKET_FILE = "#{DEPLOY_TO}/shared/unicorn.sock"
LOG_FILE = "#{RAILS_ROOT}/log/unicorn.log"
ERR_LOG = "#{RAILS_ROOT}/log/unicorn_error.log"
OLD_PID = PID_FILE + '.old'
listen SOCKET_FILE, :backlog => 1024
timeout 30
worker_processes 2
user "danchenkov", "danchenkov"
working_directory RAILS_ROOT
pid PID_FILE
stderr_path ERR_LOG
stdout_path LOG_FILE
preload_app true
GC.respond_to?(:copy_on_write_friendly=) and
GC.copy_on_write_friendly = true
before_exec do |server|
ENV["BUNDLE_GEMFILE"] = "#{rails_root}/Gemfile"
end
before_fork do |server, worker|
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
old_pid = "#{server.config[:pid]}.old"
if File.exists?(old_pid) && old_pid != server.pid
begin
sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
Process.kill(sig, File.read(old_pid).to_i)
rescue Errno::ENOENT, Errno::ESRCH
end
end
sleep 1
end
after_fork do |server, worker|
defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
end
nginx.conf
###############################################################################
#
# UNICORN UPSTREAM
#
###############################################################################
upstream unicorn_network_app_server {
server unix:/var/www/network/shared/unicorn.sock fail_timeout=0;
}
###############################################################################
#
# NETWORK - PROXY TO UNICORN ON UNIX SOCKET
#
###############################################################################
server {
listen 80;
server_name network.mydomain.ru;
client_max_body_size 1G;
access_log /var/log/nginx/network.access.log main;
error_log /var/log/nginx/network.error.log notice;
keepalive_timeout 5;
root /var/www/network/current/public;
try_files $uri/index.html $uri.html $uri @network_app;
# Main location
location @network_app {
proxy_pass http://unicorn_network_app_server;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
error_page 500 502 503 504 /500.html;
location = /500.html {
root /var/www/network/current/public;
}
}
解决方法:
我在网络服务器日志中注意到类似的消息,注意到我必须让Rails知道我没有在config / environments / production.rb中使用缓存
config.action_controller.perform_caching = false
标签:nginx,ruby-on-rails,ruby-on-rails-3,capistrano,unicorn 来源: https://codeday.me/bug/20190613/1234128.html