title: sprockets failed to prepare assets for nginx
body: <p>I want to let <code>nginx</code> serve the static files for cache task.</p>
  
  <p>But I got <code>No such file or directory</code> from nginx error log.</p>
  
  <p>It seems the css files included in <code>root-c452663d516929cd4bb4c1cd521971eb.css</code> could not be served.</p>
  
  <p>How could I fix the bug</p>
  
  <h1>production.rb</h1>
  
  <pre><code>  # Disable serving static files from the `/public` folder by default since
    # Apache or NGINX already handles this.
    #config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
    config.serve_static_files = false
  
    # Compress JavaScripts and CSS.
    config.assets.js_compressor = :uglifier
    # config.assets.css_compressor = :sass
  
    # Do not fallback to assets pipeline if a precompiled asset is missed.
    config.assets.compile = true
  </code></pre>
  
  <h1><a href="http://localhost/assets/kode/css/root-c452663d516929cd4bb4c1cd521971eb.css" rel="nofollow">http://localhost/assets/kode/css/root-c452663d516929cd4bb4c1cd521971eb.css</a></h1>
  
  <pre><code>/* Summernote */
  @import url('plugin/summernote/summernote.css');
  @import url('plugin/summernote/summernote-bs3.css');
  
  /* Sweet Alert */
  @import url('plugin/sweet-alert/sweet-alert.css');
  
  /* Data Tables */
  @import url('plugin/datatables/datatables.css');
  
  /* Chartist */
  @import url('plugin/chartist/chartist.min.css');
  
  /* Rickshaw */
  @import url('plugin/rickshaw/rickshaw.css');
  @import url('plugin/rickshaw/detail.css');
  @import url('plugin/rickshaw/graph.css');
  @import url('plugin/rickshaw/legend.css');
  </code></pre>
  
  <h1>nginx setting</h1>
  
  <pre><code>location / {
  try_files $uri @sample;
  gzip_static       on;
  expires           max;
  add_header        Cache-Control public;
  }
  
  location @sample {
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_redirect off;
      proxy_pass http://sample;
  }
    location ~* ^/assets/ {
        # Per RFC2616 - 1 year maximum expiry
        expires 1y;
        add_header Cache-Control public;
  
        # Some browsers still send conditional-GET requests if there's a
        # Last-Modified header or an ETag header even if they haven't
        # reached the expiry date sent in the Expires header.
        add_header Last-Modified "";
        add_header ETag "";
        break;
      }
  </code></pre>
  
  <h1>Error log</h1>
  
  <pre><code>2015/07/22 17:27:02 [error] 9891#0: *9 open() "/var/public/assets/kode/css/plugin/date-range-picker/daterangepicker-bs3.css" failed (2: No such file or directory), client: 118.166.217.131, server: www.localhost, request: "GET /assets/kode/css/plugin/date-range-picker/daterangepicker-bs3.css HTTP/1.1", host: "localhost", referrer: "http://localhost/assets/kode/css/root-c452663d516929cd4bb4c1cd521971eb.css"
  2015/07/22 17:27:02 [error] 9891#0: *10 open() "/var/public/assets/kode/css/plugin/rickshaw/legend.css" failed (2: No such file or directory), client: 118.166.217.131, server: www.localhost, request: "GET /assets/kode/css/plugin/rickshaw/legend.css HTTP/1.1", host: "localhost", referrer: "http://localhost/assets/kode/css/root-c452663d516929cd4bb4c1cd521971eb.css"
  2015/07/22 17:27:02 [error] 9891#0: *11 open() "/var/public/assets/kode/css/plugin/rickshaw/detail.css" failed (2: No such file or directory), client: 118.166.217.131, server: www.localhost, request: "GET /assets/kode/css/plugin/rickshaw/detail.css HTTP/1.1", host: "localhost", referrer: "http://localhost/assets/kode/css/root-c452663d516929cd4bb4c1cd521971eb.css"
  2015/07/22 17:27:02 [error] 9891#0: *5 open() "/var/public/assets/kode/css/plugin/fullcalendar/fullcalendar.css" failed (2: No such file or directory), client: 118.166.217.131, server: www.localhost, request: "GET /assets/kode/css/plugin/fullcalendar/fullcalendar.css HTTP/1.1", host: "localhost", referrer: "http://localhost/assets/kode/css/root-c452663d516929cd4bb4c1cd521971eb.css"
  </code></pre>
  
  <h1>puma.config</h1>
  
  <pre><code>app_path = File.expand_path('../', File.dirname(__FILE__))
  pidfile "#{app_path}/tmp/pids/puma.pid"
  bind "unix:///tmp/puma.lazyair.sock"
  stdout_redirect "#{app_path}/log/puma.stdout.log", "#{app_path}/log/puma.stderr.log", true
  workers Integer(ENV['WEB_CONCURRENCY'] || 6)
  threads_count = Integer(6)
  threads threads_count, threads_count
  
  preload_app!
  
  rackup      DefaultRackup
  port        ENV['PORT'] ||  3457
  
  # Default to production
  rails_env = ENV['RAILS_ENV'] || "production"
  environment rails_env
  
  on_worker_boot do
    ActiveRecord::Base.establish_connection
  end
  activate_control_app
  </code></pre>