The situation is as follows: I made a migration of a rails app from an Ubuntu server with nginx + passenger to a debian server with apache2 + passenger.
All was fine until we tested some ajax functions loading templates with handlebars.js and other scripts. It was complaining about javascript calls so I installed an nginx virtualhost serving on port 8080. Then made an apache proxy configuration on the apache virtualhost to redirect the trafic to the nginx server listening on port 8080. The original server was working fine with nginx so I though this should work, and it did.
But lately we tested more menus of the app and found that it did not work to upload files, although this is working on the apache2 if I remove the proxy lines from the virtualhost config.
This is the Apache2 virtualhost file:
<VirtualHost 217.13.81.93:443> ServerAdmin [email protected] ServerName design-union.co.uk ServerAlias www.design-union.co.uk vu2029.admin.tantosoft.com LogLevel error ErrorLog /var/log/apache2/design-union.co.uk/error.log #DocumentRoot /var/www/virtual/design-union.co.uk/htdocs DocumentRoot /var/www/virtual/design-union.co.uk/htdocs/current.new/public PassengerLogLevel 3 Alias /errors /var/www/virtual/design-union.co.uk/errors/ SuexecUserGroup vu2029 vu2029 #SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1 <FilesMatch ".+\.ph(p[3457]?|t|tml)$"> SetHandler "proxy:unix:/var/run/php5-fpm-design-union.co.uk.sock|fcgi://design-union.co.uk/" </FilesMatch> <Directory /var/www/virtual/design-union.co.uk> Options +SymLinksIfOwnerMatch Require all granted </Directory> <Directory /var/www/virtual/design-union.co.uk/htdocs> AllowOverride All Options -MultiViews </Directory> #ScriptAlias /cgi-bin/ /var/www/virtual/design-union.co.uk/cgi-bin/ <Directory /var/www/virtual/design-union.co.uk/cgi-bin> # AllowOverride AuthConfig Indexes Limit </Directory> RedirectMatch permanent ^(/(?:ftp|pma|webmail)[/]?)$ http://admin.tantosoft.com$1 ProxyRequests Off ProxyPass /stats http://localhost/stats/design-union.co.uk ProxyPassReverse /stats http://localhost/stats/design-union.co.uk ProxyPass / http://www.design-union.co.uk:4443/ ProxyPassReverse / http://www.design-union.co.uk:4443/ <Location /stats> RewriteEngine on RewriteRule ^(.+)?config=([^?&]+)(.*) $1?config=design-union.co.uk&$3 [NC,L] AuthType Basic AuthName "Statistics for domain design-union.co.uk" AuthUserFile /var/www/virtual/design-union.co.uk/.htpasswd AuthGroupFile /var/www/virtual/design-union.co.uk/.htgroup Require group statistics </Location> SSLEngine On SSLCertificateFile /var/www/imscp/gui/data/certs/design-union.co.uk.pem SSLCertificateChainFile /var/www/imscp/gui/data/certs/design-union.co.uk.pem Include /etc/apache2/imscp/design-union.co.uk.conf </VirtualHost>
This is the nginx virtualhost file:
server { server_name www.design-union.co.uk; listen 217.13.81.93:4443; listen [::]:4443; ssl on; ssl_certificate /var/www/imscp/gui/data/certs/design-union.co.uk.pem; ssl_certificate_key /var/www/imscp/gui/data/certs/design-union.co.uk.pem; root /var/www/virtual/design-union.co.uk/htdocs/current.new/public; passenger_enabled on; passenger_min_instances 1; passenger_friendly_error_pages on; passenger_user vu2029; rails_env production; client_body_buffer_size 10M; location /errors { alias /var/www/imscp/gui/public/errordocs; } error_page 401 /errors/401.html; error_page 403 /errors/403.html; error_page 404 /errors/404.html; error_page 497 https://$host:$server_port$request_uri; error_page 500 /errors/500.html; error_page 503 /errors/503.html; location ~ ^/assets/ { gzip_static on; expires 1y; add_header Cache-Control public; add_header ETag ""; break; } error_page 500 502 503 504 /server-500.html; location /server-500.html { root /var/www/nginx-default; } } passenger_pre_start http://www.design-union.co.uk;
Both virtualhosts definitions use the user vu2029 to do filesystem things, and also I changed the nginx user to run as vu2029.
If I remove the Apache2 proxy lines and run the app on apache2 + passenger, it does upload the files correctly, but fails on other javascript parts. If I add the proxy lines and run the app on nginx, it renders all fine the javascripts but fails to upload files.
I'm getting crazy. See also some of the logs from the rails production.log:
Started POST "/admin/assets.json" for 88.5.145.53 at 2017-05-09 19:02:09 +0200 Processing by Admin::AssetsController#create as JSON Parameters: {"authenticity_token"=>"7iBXhXjcL/Jp5AmeXpT9HV2B/Ilfz08z5CUf1EWkQA=", "file"=>#<ActionDispatch::Http::UploadedFile:0x007f5d58f47c68 @original_filename="walle_back.png", @content_type="image/png", @headers="Content-Disposition: form-data; name=\"file\"; filename=\"walle_back.png\"\r\nContent-Type: image/png\r\n", @tempfile=#<Tempfile:/tmp/RackMultipart20170509-18136-1o9vefd>>} MOPED: 127.0.0.1:27017 QUERY database=design_union_production collection=admins selector={"$query"=>{"_id"=>"54298de59acc936174000004"}, "$orderby"=>{:_id=>1}} flags=[:slave_ok] limit=-1 skip=0 batch_size=nil fields=nil (0.3929ms) 500: /admin/assets.json :: {"authenticity_token"=>"7iBXhXjcL/Jp5AmeXpT9HV2B/Ilfz08z5CUf1EWkQA=", "file"=>#<ActionDispatch::Http::UploadedFile:0x007f5d58f47c68 @original_filename="walle_back.png", @content_type="image/png", @headers="Content-Disposition: form-data; name=\"file\"; filename=\"walle_back.png\"\r\nContent-Type: image/png\r\n", @tempfile=#<Tempfile:/tmp/RackMultipart20170509-18136-1o9vefd>>, "action"=>"create", "controller"=>"admin/assets", "format"=>"json"} MOPED: 127.0.0.1:27017 QUERY database=design_union_production collection=pages selector={"$query"=>{"role"=>"error"}, "$orderby"=>{:_id=>1}} flags=[:slave_ok] limit=-1 skip=0 batch_size=nil fields=nil (0.8137ms) Page.ordered_slices (0.5ms) Rendered text template (0.0ms) Completed 500 Internal Server Error in 75.8ms (Views: 0.9ms)
The Firebug console log:
POST https://www.design-union.co.uk:4443/admin/assets.json 500 Internal Server Error 472ms jquery.min.js (línea 4) EncabezadosPostCookies ver fuente Cache-Control no-cache Connection keep-alive Content-Type application/json; charset=utf-8 Date Tue, 09 May 2017 17:02:09 GMT Server nginx/1.10.2 + Phusion Passenger 5.1.2 Transfer-Encoding chunked X-Powered-By Phusion Passenger 5.1.2 X-Rack-Cache invalidate, pass X-Request-Id 6e4b5a7447ed78d9b3cc24f33f2a30f8 X-Runtime 0.102857 X-UA-Compatible IE=Edge,chrome=1 status 500 Internal Server Error ver fuente Accept */* Accept-Encoding gzip, deflate, br Accept-Language en-US,en;q=0.5 Content-Length 586541 Content-Type multipart/form-data; boundary=---------------------------10471913232033507427250099373 Cookie _design_union_session=Bh7CEkiD3Nlc3Npb25faWQGOgZFVEkiJTMzZmUxYTliM2NmYjNlOWZmOGU4NTg3Y2RhMWUwYTcwBj sAVEkiGndhcmRlbi51c2VyLmFkbWluLmtleQY7AFRbB1sGVToaTW9wZWQ6OkJTT046Ok9iamVjdElkIhFUKY3lmsyTYXQAAARJIi IkMmEkMTAkWkhpZ1VLMmxtdGFXMms5cG16Ui8wZQY7AFRJIhBfY3NyZl90b2tlbgY7AEZJIjE3eGlCWGhYamNML0pwNUFtZVhwVDlIVjJCL0lsZnowOHo1Q1VmMUVXa1FBPQY7AEY %3D--11e2341939add257da345ddb03c4bac0d661b3d7; __utma=1.1509736449.1494261374.1494332932.1494339392.4 ; __utmc=1; __utmz=1.1494261374.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utma=85681676.479307049 .1494264038.1494264038.1494333556.2; __utmc=85681676; __utmz=85681676.1494264038.1.1.utmcsr=(direct) |utmccn=(direct)|utmcmd=(none); __utmb=1.60.10.1494339392; __utmt=1 Host www.design-union.co.uk:4443 Referer https://www.design-union.co.uk:4443/admin/assets User-Agent Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0 X-CSRF-Token 7iBXhXjcL/Jp5AmeXpT9HV2B/Ilfz08z5CUf1EWkQA= X-Requested-With XMLHttpRequest "NetworkError: 500 Internal Server Error - https://www.design-union.co.uk:4443/admin/assets.json" assets.json
The files are uploaded into the server's /tmp/ folder, but then it is not moved to the application system/files/ folder. I though it could be permissions, and for testing I chmod the full project files and dirs 777 with no luck. Both nginx and the apache process are running from the user vu2029.
This is the log of the standalone Passenger running on port 3000 serving the same app:
Started POST "/admin/assets.json" for 88.5.145.53 at 2017-05-11 12:25:17 +0200 Processing by Admin::AssetsController#create as JSON Parameters: {"authenticity_token"=>"7iBXhXjcL/Jp5AmeXpT9HV2B/Ilfz08z5CUf1EWkQA=", "file"=>#<ActionDispatch::Http::UploadedFile:0x0000000680f650 @original_filename="ios_mosaic_hor.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"file\"; filename=\"ios_mosaic_hor.jpg\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#<Tempfile:/tmp/RackMultipart20170511-15343-13plto5>>} MOPED: 127.0.0.1:27017 QUERY database=design_union_production collection=admins selector={"$query"=>{"_id"=>"54298de59acc936174000004"}, "$orderby"=>{:_id=>1}} flags=[:slave_ok] limit=-1 skip=0 batch_size=nil fields=nil (0.4151ms) App 15343 stdout: Command :: identify -format %wx%h '/tmp/ios_mosaic_hor20170511-15343-18f5uzb.jpg[0]' App 15343 stdout: Command :: identify -format %m '/tmp/ios_mosaic_hor20170511-15343-18f5uzb.jpg[0]' App 15343 stdout: Command :: identify -format %m '/tmp/ios_mosaic_hor20170511-15343-18f5uzb.jpg[0]' App 15343 stdout: Command :: convert '/tmp/ios_mosaic_hor20170511-15343-18f5uzb.jpg[0]' -resize "256x256>" -strip -density 72x72 -depth 8 '/tmp/ios_mosaic_hor20170511-15343-18f5uzb20170511-15343-1jwvw6t' App 15343 stdout: Command :: file -b --mime '/tmp/ios_mosaic_hor20170511-15343-18f5uzb20170511-15343-1jwvw6t' App 15343 stdout: Command :: identify -format %wx%h '/tmp/ios_mosaic_hor20170511-15343-18f5uzb.jpg[0]' App 15343 stdout: Command :: identify -format %wx%h '/tmp/ios_mosaic_hor20170511-15343-18f5uzb20170511-15343-1jwvw6t20170511-15343-1gl5n8l[0]' MOPED: 127.0.0.1:27017 INSERT database=design_union_production collection=assets documents=[{"_id"=>"59143c0d21232f27e7000002", "file_dimensions"=>{"original"=>"1130x960", "admin"=>"256x217"}, "page_cache"=>[], "file_file_name"=>"ios_mosaic_hor.jpg", "file_content_type"=>"image/jpeg", "file_file_size"=>194168, "file_fingerprint"=>"4fbef76166cb06ae99e9c240e4a189f3", "file_updated_at"=>2017-05-11 10:25:17 UTC, "tags"=>"", "_keywords"=>["ios", "mosaic", "hor", "jpg"], "updated_at"=>2017-05-11 10:25:17 UTC, "created_at"=>2017-05-11 10:25:17 UTC}] flags=[] (0.2253ms) App 15343 stdout: [paperclip] Saving attachments. 500: /admin/assets.json :: {"authenticity_token"=>"7iBXhXjcL/Jp5AmeXpT9HV2B/Ilfz08z5CUf1EWkQA=", "file"=>#<ActionDispatch::Http::UploadedFile:0x0000000680f650 @original_filename="ios_mosaic_hor.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"file\"; filename=\"ios_mosaic_hor.jpg\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#<Tempfile:/tmp/RackMultipart20170511-15343-13plto5>>, "action"=>"create", "controller"=>"admin/assets", "format"=>"json"} MOPED: 127.0.0.1:27017 QUERY database=design_union_production collection=pages selector={"$query"=>{"role"=>"error"}, "$orderby"=>{:_id=>1}} flags=[:slave_ok] limit=-1 skip=0 batch_size=nil fields=nil (0.4716ms) Page.ordered_slices (0.3ms) Rendered text template (0.0ms) Completed 500 Internal Server Error in 99.7ms (Views: 0.6ms)
The files get uploaded to /tmp folder, but looks like it is not moved to the app files folder. When running the app in Apache2 it all works well. I'm stuck. Any help?
Edit:
/var/log/nginx/error.log:
App 26490 stdout: Command :: identify -format %wx%h '/tmp/walle_back20170511-26490-1ka42xa.png[0]' App 26490 stdout: [paperclip] An error was received while processing: #<Paperclip::Errors::CommandNotFoundError: Could not run the `identify` command. Please install ImageMagick.> App 26490 stdout: Command :: identify -format %wx%h '/tmp/walle_back20170511-26490-1ka42xa.png[0]'
I'm checking by command line and the "identify command is installed on the server, all the imagemagick package is installed. Permissions to access the file, or the identify file is not accesible by the paperclip module?