资产没有显示Rails 4 puma& nginx(AWS EC2)

时间:2015-09-19 20:33:33

标签: nginx amazon-ec2 ubuntu-14.04 ruby-on-rails-4.2 puma

我有一个Rails 4.2.0,Ruby 2.2.1p85(ubuntu 14.04),Puma 2.11.1和nginx 1.8作为反向代理。

如果我执行:

$ 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)。

这是我的配置:

$ cat /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;
    }
}

$ cat /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/*;
}

$ cat config / environments / 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

$ cat /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 个答案:

没有答案