Resolvido: no final, foi uma configuração de caminho da gema Paperclip. Eu adicionei o seguinte ao arquivo config / environments / production.rb:
Paperclip.options[:command_path] = "/usr/bin"
A situação é a seguinte: Eu fiz uma migração de um aplicativo rails de um servidor Ubuntu com nginx + passageiro para um servidor debian com apache2 + passageiro.
Tudo estava bem até que testamos algumas funções do ajax carregando modelos com handlebars.js e outros scripts. Estava reclamando sobre as chamadas javascript, então eu instalei um virtualhost nginx servindo na porta 8080. Em seguida, fiz uma configuração do proxy apache no virtualhost apache para redirecionar o tráfego para o servidor nginx ouvindo na porta 8080. O servidor original estava funcionando bem com nginx embora isso deva funcionar, e foi o que aconteceu.
Mas ultimamente testamos mais menus do aplicativo e descobrimos que ele não funcionava para fazer upload de arquivos, embora isso esteja funcionando no apache2 se eu remover as linhas de proxy da configuração virtualhost.
Este é o arquivo virtualhost do Apache2:
<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>
Este é o arquivo nginx virtualhost:
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;
Ambas as definições de virtualhosts usam o usuário vu2029 para fazer coisas do sistema de arquivos, e também alterei o usuário nginx para executar como vu2029.
Se eu remover as linhas de proxy do Apache2 e executar o aplicativo no apache2 + passenger, ele fará o upload dos arquivos corretamente, mas falhará em outras partes do javascript. Se eu adicionar as linhas de proxy e executar o aplicativo no nginx, ele renderiza todos os arquivos do javascripts, mas não faz o upload de arquivos.
Estou ficando louco. Veja também alguns dos logs do trilho 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)
O log do console do Firebug:
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
Os arquivos são enviados para a pasta / tmp / do servidor, mas não são movidos para o sistema de aplicativos / arquivos / pasta. Eu pensei que poderia ser permissões, e para testar eu chmod os arquivos do projeto completo e dirs 777 sem sorte. Tanto o nginx quanto o processo do apache estão sendo executados a partir do usuário vu2029.
Este é o log do Passenger autônomo em execução na porta 3000 que atende o mesmo aplicativo:
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)
Os arquivos são enviados para a pasta / tmp, mas parece que não foram movidos para a pasta de arquivos do aplicativo. Ao executar o aplicativo no Apache2, tudo funciona bem. Estou preso. Alguma ajuda?
Editar:
/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]'
Estou verificando pela linha de comando e o comando "identify está instalado no servidor, todo o pacote imagemagick está instalado. Permissões para acessar o arquivo ou o arquivo de identificação não é acessível pelo módulo de clipe de papel?