Carrierwave + NGINX rails production images not displaying
<p>I've deployed a rails app that allows a user to upload a photo and have it display on another page, fairly simple. I tested it in development, the image uploads to the public folder and displays properly. In production and deployed the image uploads to the server but isn't being rendered on the page. </p>

<p>404 errors for only the images I've uploaded, path looks like this:</p>

<pre><code> http://IP-OF-APP/uploads/blog/name-of-image.jpg
</code></pre>

<p>I read in another S.O. article mentioning setting a production config serve_static_files as true. This didn't fix the problem. </p>

<p>I thought it might be a server configuration with NGINX not picking up the uploads path here is my /sites-default/nginx.conf file.</p>

<pre><code>upstream app {
  server unix: /home/deploy/MYAPPNAME/shared/tmp/sockets/puma.sock fail_timeout=0;
}

server {
  listen 80;
  server_name IP_ADDRESS_OF_SERVER;

  root /home/deploy/MYAPPNAME/public;

  location @app {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $host;
    proxy_pass http://app;
    proxy_redirect off;
  }

  location ~ ^/(assets)/ {
    root /home/deploy/MYAPPNAME/shared/public
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  location ~ ^/uploads/ {
    root /home/deploy/MYAPPNAME/shared/public;
    expires 24h;
    add_header Cache-Control public;
    break;
  }

  location ~ ^/(fonts|system)/favicon.ico/robots.txt {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
  keepalive_timeout 10;
}
</code></pre>

<p>I also thought it might be that the image isn't uploading to the server correctly so I SSH'd into the server and found the image uploaded living in:</p>

<pre><code>home/deploy/MYAPPNAME/shared/public/uploads/blog/name-of-image.jpg
</code></pre>

<p>Also found what I assume to be the same image in:</p>

<pre><code>home/deploy/MYAPPNAME/current/public/uploads/blog/name-of-image.jpg
</code></pre>

<p>My uploader looks like this:</p>

<pre><code>class BlogUploader &lt; CarrierWave::Uploader::Base
  include CarrierWave::MiniMagick

  storage :file

  def store_dir
     'uploads/blog'
  end

  def extension_whitelist
     %w(jpg jpeg gif png)
  end

  process :resize_to_fit =&gt; [825, 825]

  #titles are validated to be unique
  def filename
     "#{model.title}"+".#{file.extension}" if original_filename.present?
  end
end
</code></pre>

<p>using</p>

<pre><code>Rails 4.2.6
Ruby 2.3.0
Carrierwave 0.11.0
</code></pre>

<p><strong>EDIT</strong></p>

<p>All of the other static images, CSS and JS are displaying and rendering properly. </p>

<p>The NGINX error when rending the upload image produces this:</p>

<pre><code>   2016/04/29 17:32:34 [error] 4993#0: *23 open()  "/home/deploy/MYAPPNAME/shared/public/assets/uploads/blog/name-of-image.jpg" fails (2: no such file or directory), client: *******, server: SERVER_IP, request: "GET /assets/uploads/blog/name-of-image.jpg HTTP/1.1", host: "SERVER_IP"
</code></pre>