资产预先编译但没有显示puma& nginx(Rails 4)

时间:2015-07-19 19:28:58

标签: ruby-on-rails nginx puma

当我这样做时,在我的本地机器上:

RAILS_ENV=production bundle exec rake assets:precompile
RAILS_ENV=production bundle exec puma -e production

一切正常。但是,我在docker容器中拥有与nginx一起运行的完全相同的应用程序。我可以看到application.css&使用chrome dev工具在assets文件夹中的application.js文件,它们不是空的。但我有一个没有css / js的页面,它应该与nginx有关但我真的很困惑。

/var/etc/nginx/nginx.conf:

user app sudo;

http{

  upstream app {
    server unix:/home/app/puma.sock fail_timeout=0;
  }

  server {
    listen 80 default;
    root /home/app/app/public;
    try_files $uri/index.html $uri @app;

    location @app {
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_redirect off;
      proxy_pass http://app;
    }
  }

  }

  events {worker_connections 1024;}

配置/环境/ production.rb:

Rails.application.configure do
  ...
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true
  config.serve_static_files = true
  config.assets.js_compressor = :uglifier
  config.assets.compile = false
  config.assets.digest = true
  ...
  end

请毫不犹豫地提出任何建议。 :)

更新: 我刚刚意识到我的控制台中有这两个错误:

new:11 Resource interpreted as Stylesheet but transferred with MIME type text/plain: "http://localhost/assets/application-5574b338d88d13681ef38b9b0800bc47.css".
new:12 Resource interpreted as Script but transferred with MIME type text/plain: "http://localhost/assets/application-ea59e17aff7f15a316e3e03d49f3daf4.js".

1 个答案:

答案 0 :(得分:0)

如果您希望nginx为您的静态资源提供服务,则需要设置config.serve_static_files = false,以便Rails不会尝试为您执行此操作。

相关问题