【问题标题】:Rails 4 assets:precompile not working Nginx + Thin configurationRails 4 assets:precompile not working Nginx + Thin 配置
【发布时间】:2014-04-18 16:05:33
【问题描述】:

请帮助我。 我在 vps 上运行 rails4 应用程序。

我的 nginx 配置很薄

upstream myapp {
  server 127.0.0.1:3000;
  server 127.0.0.1:3001;
  server 127.0.0.1:3002;
}
server {
  listen   80;
  server_name .example.com;

  access_log /var/www/myapp.example.com/log/access.log;
  error_log  /var/www/myapp.example.com/log/error.log;
  root     /var/www/myapp.example.com;
  index    index.html;

  location / {
    proxy_set_header  X-Real-IP  $remote_addr;
    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header  Host $http_host;
    proxy_redirect  off;
  try_files /system/maintenance.html $uri $uri/index.html $uri.html @ruby;
 }

  location @ruby {
   proxy_pass http://myapp;
  }
}

这是我的生产环境设置

# Disable Rails's static asset server (Apache or nginx will already do this).
 config.serve_static_assets = true

 # Compress JavaScripts and CSS.
 config.assets.js_compressor = :uglifier
 #  config.assets.css_compressor = :sass

  # Do not fallback to assets pipeline if a precompiled asset is missed.
 config.assets.compile = true
 config.assets.precompile = ['*.js', '*.css', '*.css.erb']

在 public/assets/ 我可以看到编译后的 js css 和图像,比如 manydigits.png 但是当我访问我的网站时,资产中有 404

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-4 nginx thin


    【解决方案1】:
      location ~ ^/(assets)/{
         root /var/www/myapp.example.com/public;
         expires max;
         add_header Cache-Control public;
      }
    

    nginx 配置中的这段代码修复了我的资产问题

    【讨论】:

      猜你喜欢
      • 2015-11-26
      • 2013-04-06
      • 2012-08-04
      • 2013-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-19
      • 1970-01-01
      相关资源
      最近更新 更多