Question

Je reçois un cache: [GET /] miss Message d'erreur pour mon application Rails 3.2.

J'utilise Nginx comme proxy sur Unicorn Server et je déploie avec Capistrano. Lorsque je commence le serveur, je reçois beaucoup d'erreurs de répétition comme celle ci-dessus. Capistrano précompile définitivement les actifs pendant le déploiement. J'inclus les fichiers de configuration ci-dessous (désolé d'être verbeux).

Des idées ou au moins un indice pour découvrir ce qui ne va pas?

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;
  }
}
Était-ce utile?

La solution

J'ai remarqué des messages similaires dans mes journaux de serveurs Web et j'ai remarqué que je devais faire savoir aux rails que je n'utilise pas de mise en cache dans config/environments/production.rb

config.action_controller.perform_caching = false

Autres conseils

'config.action_controller.perform_caching' est défini sur false si vous exécutez en mode développement. Cet drapeau est normalement défini dans la config / * Environments / *. RB 'correspondant et la mise en cache est désactivée par défaut pour le développement et le test, et activée pour la production.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top