1

実稼働サーバー用のnginx+unicorn +railsを備えたRailsS​​tackを使用していますが、テスト目的でVagrantの下にステージングしています。これを行っているときに、railsアプリケーションの奇妙な動作に遭遇しました。この動作では、1つまたは他のアセットが提供されていない、つまりapplication.cssが提供されていないため、スタイルが適用されていない状態でページ全体が表示されます。

問題をグーグルで調べたところ、VagrantのFSドライバーが完全に実装されておらず、Apacheの使用中に問題が発生することがわかりました(nginxへの言及は見つかりませんでした)。この問題の解決策は、sendfileをオフにしてsendfileを無効にすることでした。構成ファイルに。そして...それはうまくいきませんでした。

さらに、ログ(Rails、unicorn、nginx)を調べたところ、ファイルが提供されていない場合、どのログにもそのファイルについての言及がないことがわかりました。これにより、VagrantがVMを介してrailsアプリフォルダーを共有するために使用するメカニズムに問題がある可能性があるという疑問が生じました。vagrantのWebサイトで説明されているように、VagrantはVirtual Boxの共有フォルダーを使用します。これは他の方法(ここに示す)と比較して非常に低速であり、回避策はNFS共有フォルダーを設定することです。そこで、NFSを試してみることにしましたが、結果は同じでした。残念ながら、一部のアセットは提供されません。

誰かがこれについて何か考えを持っていますか?私はかなり長い間検索しましたが、ここで説明したものに追加するポインタは見つかりませんでした。

私が使用しているもの:

Mac OS X 10.6.8 + rbenv(開発用)

Vagrant + nginx + rbenv +ユニコーン+バンドラー(ステージングまで)

unicorn.rb

rails_env         = ENV['RAILS_ENV'] || 'production'
app_directory     = File.expand_path(File.join(File.dirname(__FILE__), ".."))

worker_processes 4
working_directory app_directory

listen "/tmp/appname.sock", :backlog => 64
#listen "#{app_directory}/tmp/sockets/appname.sock", :backlog => 64

timeout 30

pid "#{app_directory}/tmp/pids/unicorn.pid"

stderr_path "#{app_directory}/log/unicorn.stderr.log"
stdout_path "#{app_directory}/log/unicorn.stdout.log"

preload_app true
GC.respond_to?(:copy_on_write_friendly=) and
  GC.copy_on_write_friendly = true

before_fork do |server, worker|
  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.connection.disconnect!
end

after_fork do |server, worker|
  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.establish_connection
end

/ etc / nginx / sites-enabled / appname

upstream unicorn_server {
        server unix:/tmp/appname.sock fail_timeout=0;
}

server {
    listen 80;
    client_max_body_size 4G;
    server_name _;

    keepalive_timeout 5;

    # Location of our static files
    root /home/appname/www/current/public;

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

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

    error_page 500 502 503 504 /500.html;
    location = /500.html {
      root /home/hemauto/www/current/public;
    }
  }
4

0 に答える 0