2015-09-19 2 views
1

У меня есть Rails 4.2.0, Ruby 2.2.1p85 (ubuntu 14.04), с Puma 2.11.1 и nginx 1.8 в качестве обратного прокси.Активы, не показывающие с рельсами 4 puma & nginx (AWS EC2)

Если я выполняю:

$ rvmsudo rails server -b 172.31.555.555 -p 80 -e production 

с

$ sudo service nginx stop 

Все в порядке.

... но если я пытаюсь с Nginx в середине:

$ rvmsudo bundle exec puma -e production -b unix:///var/run/myapp.sock 

с

$ sudo service nginx start 

Страницы обнаружился, но не активы (CSS, JS, JPG, PNG) ,

Это моя конфигурация:

$ кошки /etc/nginx/sites-enabled/myapp.work:

upstream myapp.work { 
    server unix:///var/run/myapp.sock; 
} 

server { 
    listen  80; 
    server_name myapp.work; 
    root /var/www/myapp/public; 

    location/{ 
     proxy_pass http://myapp.work; # match the name of upstream directive which is defined above 
     proxy_set_header Host $host; 
     proxy_set_header X-Real-IP $remote_addr; 
     #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    } 

    location ~* ^/assets/ { 
     expires 1y; 
     add_header Cache-Control public; 
     add_header Last-Modified ""; 
     #add_header ETag ""; 
     break; 
    } 
} 

$ кошки /etc/nginx/nginx.conf:

user nginx; 
worker_processes 1; 

error_log /var/log/nginx/error.log warn; 
pid  /var/run/nginx.pid; 


events { 
    worker_connections 1024; 
} 


http { 
    include  /etc/nginx/mime.types; 
    default_type application/octet-stream; 

    log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 
         '$status $body_bytes_sent "$http_referer" ' 
         '"$http_user_agent" "$http_x_forwarded_for"'; 

    access_log /var/log/nginx/access.log main; 

    sendfile  on; 
    #tcp_nopush  on; 

    keepalive_timeout 65; 

    #gzip on; 

    include /etc/nginx/conf.d/*.conf; 
    include /etc/nginx/sites-enabled/*; 
} 

$ кошка конфигурации/среда/production.rb

Rails.application.configure do 
    config.cache_classes = true 
    config.eager_load = true 
    config.consider_all_requests_local  = false 
    config.action_controller.perform_caching = true 
    config.serve_static_files = false 
    config.assets.js_compressor = :uglifier 
    config.assets.css_compressor = :sass 
    config.assets.compile = true 
    config.assets.digest = true 
    config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX 
    config.log_level = :debug 
    config.action_mailer.raise_delivery_errors = true 
    config.action_mailer.default_url_options = { host: 'http://52.88.555.555', port: 80 } 
    config.action_mailer.delivery_method = :smtp 
    config.action_mailer.smtp_settings = { 
    :address => "mail.mymail.com", 
    :port => 587, 
    :domain => "mydomain.com", 
    :user_name => ENV["txa_mail"], 
    :password => ENV["txa_pass"], 
    :authentication => :login, 
    :enable_starttls_auto => true, 
    :openssl_verify_mode => 'none' 
    } 
    config.i18n.fallbacks = true 
    config.active_support.deprecation = :notify 
    config.log_formatter = ::Logger::Formatter.new 
    config.active_record.dump_schema_after_migration = false 
end 

$ кошка /var/log/nginx/error.log

2015/09/19 19:16:44 [error] 20716#0: *1 open() "/var/www/myapp/public/assets/application-6c87dce3bc16e6e98066ff6c6acd127148ff8009271165207404a1fcdd25989f.css" failed (2: No such file or directory), client: 190.48.126.22, server: myapp.work, request: "GET /assets/application-6c87dce3bc16e6e98066ff6c6acd127148ff8009271165207404a1fcdd25989f.css HTTP/1.1", host: "myapp.work", referrer: "http://myapp.work/" 
2015/09/19 19:16:44 [error] 20716#0: *1 open() "/var/www/myapp/public/assets/application-609d6f1d02655c07f8c3b280c986f2ff351f6105e327145be40faff36df2bb8c.js" failed (2: No such file or directory), client: 190.48.126.22, server: myapp.work, request: "GET /assets/application-609d6f1d02655c07f8c3b280c986f2ff351f6105e327145be40faff36df2bb8c.js HTTP/1.1", host: "myapp.work", referrer: "http://myapp.work/" 
2015/09/19 19:16:44 [error] 20716#0: *3 open() "/var/www/myapp/public/assets/logo-google-feed7f037310a2e6fd952385e026f6176f23b5a02fab50f2823020ae52b8cc3b.png" failed (2: No such file or directory), client: 190.48.126.22, server: myapp.work, request: "GET /assets/logo-google-feed7f037310a2e6fd952385e026f6176f23b5a02fab50f2823020ae52b8cc3b.png HTTP/1.1", host: "myapp.work", referrer: "http://myapp.work/" 
2015/09/19 19:16:45 [error] 20716#0: *1 open() "/var/www/myapp/public/assets/home01h-2416d3a81632df5d1854647d2eab530f81c6349dd4d15eda6c010592aafec815.jpg" failed (2: No such file or directory), client: 190.48.126.22, server: myapp.work, request: "GET /assets/home01h-2416d3a81632df5d1854647d2eab530f81c6349dd4d15eda6c010592aafec815.jpg HTTP/1.1", host: "myapp.work", referrer: "http://myapp.work/" 
2015/09/19 19:16:45 [error] 20716#0: *4 open() "/var/www/myapp/public/assets/home01v-db52d62784e9f4c85aaa42a67e77789cc414a13e7b9cb53807a46e81444c336a.jpg" failed (2: No such file or directory), client: 190.48.126.22, server: myapp.work, request: "GET /assets/home01v-db52d62784e9f4c85aaa42a67e77789cc414a13e7b9cb53807a46e81444c336a.jpg HTTP/1.1", host: "myapp.work", referrer: "http://myapp.work/" 
2015/09/19 19:16:45 [error] 20716#0: *3 open() "/var/www/myapp/public/assets/icon-f2-3b43c9fd8a0c8013f9044a1e87697e4297ca45bd6f197ce3cca5ec4c2ee2183a.png" failed (2: No such file or directory), client: 190.48.126.22, server: myapp.work, request: "GET /assets/icon-f2-3b43c9fd8a0c8013f9044a1e87697e4297ca45bd6f197ce3cca5ec4c2ee2183a.png HTTP/1.1", host: "myapp.work", referrer: "http://myapp.work/" 
2015/09/19 19:16:45 [error] 20716#0: *1 open() "/var/www/myapp/public/assets/icon-t2-0dcd845909680a6ab701bc0e9df0b5dc4b6dae79dabbff689471dc63e7088547.png" failed (2: No such file or directory), client: 190.48.126.22, server: myapp.work, request: "GET /assets/icon-t2-0dcd845909680a6ab701bc0e9df0b5dc4b6dae79dabbff689471dc63e7088547.png HTTP/1.1", host: "myapp.work", referrer: "http://myapp.work/" 

Пожалуйста, помогите мне !! Я пробовал много вещей в течение двух дней, и ничего не работало.

Заранее благодарен!

+0

просто принимая выстрел в темноте, но вы сделали прекомпиляцию своих активов для приложения рельсов в производственной среде не так ли? В частности, взгляните на это, http://guides.rubyonrails.org/asset_pipeline.html#precompiling-assets – Chris

+0

Да, это работает! Я запускаю «RAILS_ENV = производственный бит/рейк-активы: прекомпилировать». Теперь мне нужно только знать, как его автоматизировать. – Gustavo

+0

Я действительно не знаю, почему nginx не делает это, как это делает Puma. Благодаря! – Gustavo

ответ

1

Выполните следующую команду, RAILS_ENV=production bin/rake assets:precompile