Nginx nginx 和 passenger 怎么在 prodution 里面处理 gem 里面的 assets 呢

inetufo · 2012年09月11日 · 最后由 leomao10 回复于 2012年09月25日 · 3495 次阅读

sidekiq 的后台管理页面 CSS 和 JS 文件都不能加载

<link href="/sidekiq/assets/application.css" media="screen" rel="stylesheet" type="text/css" />
<script src="/sidekiq/assets/application.js" type="text/javascript"></script>

CSS 和 JS 是这个路径,nginx 貌似无法处理

error log 里面显示 X-Accel-Mapping header missing nginx.conf 已配置

location ~ ^/(assets|images|javascripts|stylesheets|swfs|system)/ {
    gzip_static     on;
    expires         max;
    add_header      Cache-Control public;
    add_header      Last-Modified "";
    add_header      ETag "";
    break;
}

解决了,原来是设置了 cache_store 为 memcached,但是 memcached 没有开启

@inetufo 能贴一下你 nginx.conf 是怎么设 cache_store 么?现在正遇到这个问题

#2 楼 @leomao10 不是 nginx 设置的 cache_store 是 rails production.rb 里面设置的 cache_store

config.cache_store = :mem_cache_store

这个选项会影响到 nginx 的么?

发现之前用 resque 其实是遇到过相同的问题的: https://github.com/defunkt/resque/issues/418

在我们的生产环境中,nginx.conf 有这段代码:

location ~* ^.+.(js|swf|css|jpg|jpeg|gif|png)$ {
    root project/current/public;
    if (-f $request_filename) {
      expires modified +5d;
    }
}

但似乎只要把 root 那行去掉就没问题了

需要 登录 后方可回复, 如果你还没有账号请 注册新账号