Nginx, Passenger, Rails - File Uploads Do Not Work

October 31, 2014 2.1k views

I am not able to get file uploads working under Nginx with PassengerL. I am using Carrierwave as the uploader, but that shouldn't make a difference.

The error on the production.log:

F, [2014-10-31T14:05:41.938864 #16078] FATAL -- : 
Errno::ENOENT (No such file or directory - identify):
  app/controllers/adults_controller.rb:44:in `update'

There are no errors in /var/log/nginx/errors.log

Her is my server Nginx site config:

server {
    listen 80;
    server_name www.mysite.in;
    root /home/deploy/mysite/current/public;
    passenger_enabled on;
    passenger_ruby /home/deploy/.rvm/gems/ruby-2.1.4/wrappers/ruby;
    passenger_user deploy;
}


server {
    listen 443 ssl;
    server_name www.mysite.in;
    root /home/deploy/mysite/current/public;
    passenger_enabled on;
    passenger_ruby /home/deploy/.rvm/gems/ruby-2.1.4/wrappers/ruby;
    passenger_user deploy;


    ssl on;
    ssl_certificate      /etc/nginx/ssl/www_mysite_in.crt;
    ssl_certificate_key  /etc/nginx/ssl/myserver.key;


    ssl_protocols        TLSv1 TLSv1.1 TLSv1.2;


    #Disables all weak ciphers
    ssl_ciphers 'AES256+EECDH:AES256+EDH';


    # Specifies that server ciphers should be preferred over client (e.g. browser) ciphers when using SSL/TLS.
    ssl_prefer_server_ciphers on;


    ssl_session_cache shared:SSL:10m;


    ssl_stapling on;
    ssl_stapling_verify on;
    resolver 8.8.4.4 8.8.8.8 valid=300s;
    resolver_timeout 10s;


    passenger_set_cgi_param HTTP_X_FORWARDED_PROTO https;
}

I can verify that the upload is received and saved into /tmp

-rw-------  1 deploy deploy  7093 Oct 31 17:21 RackMultipart20141031-11691-14busua
-rw-------  1 deploy deploy  7093 Oct 31 17:21 mini_magick20141031-11691-w6gmhc.gif

And I double-checked the permission on /tmp

drwxrwxrwt   4 root root       4096 Oct 31 17:21 tmp

So, all that looks good. So there must be something in the handoff between Nginx and rails app, that the rails app can not read the file. My app is running as the 'deploy' user.

Any ideas would be appreciated.

1 comment
2 Answers

The error is referencing ImageMagick's identify command. Either imagemagick is not installed, or the path to the command is not specified in your CarrierWave initializer.

I gave up. Blew away the image and installed a new one. All is well.

Have another answer? Share your knowledge.