Rails忽略config.action_dispatch.x_sendfile_header?使用Thin + Nginx

unr*_*ity 5 ruby-on-rails nginx thin ruby-on-rails-3

我已经建立了一个运行Rails 3.1.0rc6,Thin和Nginx的生产环境.

出于某种原因,将其具有config.action_dispatch.x_sendfile_header = "X-Accel-Redirect"config/environments/production.rb,Rails的似乎完全忽略它; 资产未被提供,一个文件的响应标头如下:

Server: nginx/1.0.5
Date: Sun, 28 Aug 2011 00:26:08 GMT
Content-Type: image/png
Content-Length: 0
Cache-Control: no-cache
Last-Modified: Sat, 27 Aug 2011 23:47:35 GMT
Etag: "af4810c52cb323d9ed061d1db5b4f296"
X-UA-Compatible: IE=Edge,chrome=1
X-Sendfile: /var/www/***/app/assets/images/bg-linen-light.png
X-Runtime: 0.004595
X-Content-Digest: da39a3ee5e6b4b0d3255bfef95601890afd80709
Age: 0
X-Rack-Cache: stale, valid, store

200 OK
Run Code Online (Sandbox Code Playgroud)

所以似乎Rails仍在设置X-Sendfile标题.我已经尝试添加sendfile_header行config/application.rb,但我猜它正在被覆盖或被忽略.

我的瘦身yml文件:

--- 
chdir: /var/www/***
environment: production
address: 0.0.0.0
port: 3000
timeout: 30
log: log/thin.log
pid: tmp/pids/thin.pid
max_conns: 1024
max_persistent_conns: 512
require: []

wait: 30
servers: 1
daemonize: true
Run Code Online (Sandbox Code Playgroud)

Nginx vhost:

upstream *** {
    server 127.0.0.1:3000;
}

server {
    listen 80;
    server_name ***;
    root /var/www/***/public;
    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;

        if (-f $request_filename/index.html) {
            rewrite (.*) $1/index.html break;
        }

        if (-f $request_filename.html) {
            rewrite (.*) $1.html break;
        }

        if (!-f $request_filename) {
            proxy_pass http://***;
            break;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我已经尝试/etc/init.d/thin stop过几次再启动它,但无济于事.

unr*_*ity 3

我在以下地方遇到过这个production.log

Started GET "/assets/bg-linen-light.png" for ***** at 2011-08-28 11:04:42 +0400
Served asset /bg-linen-light.png - 304 Not Modified (102ms)
Run Code Online (Sandbox Code Playgroud)

问题是浏览器之前 x_sendfile_header已请求该文件被更改为应有的内容,因此似乎 Rails(和/或浏览器)在更改变量后绝对不执行任何操作。

通过转至rails console并键入解决了该问题Rails.cache.clear。之后硬刷新就解决了问题!

Started GET "/assets/bg-linen-light.png" for ***** at 2011-08-28 11:06:06 +0400
Served asset /bg-linen-light.png - 200 OK (4ms)
Run Code Online (Sandbox Code Playgroud)