Ruby on rails 3 配置Nginx以使用Rails 3资产管道

Ruby on rails 3 配置Nginx以使用Rails 3资产管道,ruby-on-rails-3,nginx,Ruby On Rails 3,Nginx,我正在尝试将Nginx配置为与Rails 3资产管道一起使用 http { passenger_root /home/ubuntu/.rvm/gems/ruby-1.9.3-p327/gems/passenger-3.0.18; passenger_ruby /home/ubuntu/.rvm/wrappers/ruby-1.9.3-p327/ruby; include mime.types; default_type application/oc

我正在尝试将Nginx配置为与Rails 3资产管道一起使用

http {
    passenger_root /home/ubuntu/.rvm/gems/ruby-1.9.3-p327/gems/passenger-3.0.18;
    passenger_ruby /home/ubuntu/.rvm/wrappers/ruby-1.9.3-p327/ruby;

    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  myprojecthost.com *.myprojecthost.com;
        #charset koi8-r;

        #access_log  logs/host.access.log  main;
        root /var/www/<my proj>/current/public;

        location / {
            passenger_enabled on;
            rails_env staging;
                root /var/www/<my proj>/current/public;
        }

        location ~ ^/(assets)/{
                root /var/www/<my proj>/current/public;
                expires max;
                add_header Cache-Control public;
        }
      }
  }
我的css文件返回404错误。 如果我删除“location~^/(assets)/{”块,它工作得很好,但速度非常慢


有人能帮我吗?

你在预编译你的资产吗?
rake资产:clean
rake资产:precompile

是的,它们都在那里。如果我去.com/assets/home-6993afd6c1687aa045152d0420e1cd9f.css,我会得到一个404错误,但是如果我去/var/www/myserver/current/public/assets/home-6993afd67aa045152d20e1cd9f.css,我会得到一个404错误文件就在那里我用过这个,它很有效,但是我找不到和你贴的有什么不同。
MyProj::Application.configure do
  # Code is not reloaded between requests
  config.cache_classes = true

  # Full error reports are disabled and caching is turned on
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true

  # Disable Rails's static asset server (Apache or nginx will already do this)
  config.serve_static_assets = true

  # Compress JavaScripts and CSS
  config.assets.compress = true

  # Don't fallback to assets pipeline if a precompiled asset is missed
  config.assets.compile = true

  # Generate digests for assets URLs
  config.assets.digest = true

  # Defaults to Rails.root.join("public/assets")
  # config.assets.manifest = YOUR_PATH

  # Specifies the header that your server uses for sending files
  # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
  config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx

  # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
  # config.force_ssl = true

  # See everything in the log (default is :info)
  config.log_level = :debug

  # Use a different logger for distributed setups
  # config.logger = SyslogLogger.new

  # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
  # the I18n.default_locale when a translation can not be found)
  config.i18n.fallbacks = true

  # Send deprecation notices to registered listeners
  config.active_support.deprecation = :notify
end