ruby-on-rails - Rails 忽略 config.action_dispatch.x_sendfile_header?使用 Thin + Nginx

标签 ruby-on-rails ruby-on-rails-3 nginx thin

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

出于某种原因,设置了 config.action_dispatch.x_sendfile_header = "X-Accel-Redirect"config/environments/production.rb ,Rails 似乎完全忽略了它;未提供 Assets ,并且一个文件的响应 header 如下:

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

所以看起来 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

Nginx虚拟主机:
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;
        }
    }
}

我已经试过了 /etc/init.d/thin stop然后重新启动几次,无济于事。

最佳答案

我在 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)

问题是浏览器在 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)

关于ruby-on-rails - Rails 忽略 config.action_dispatch.x_sendfile_header?使用 Thin + Nginx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7218294/

相关文章:

ruby-on-rails - 编辑链接不适用于编辑 ruby​​ on rails 博客中的评论

ruby-on-rails - while循环在rails中创建多条记录

ruby-on-rails - Rails 3 Engine - 使用主应用程序中的模型?

php - 如何使用具有组写入权限的 file_put_contents 创建文件?

configuration - 重新加载 Nginx 配置

ruby-on-rails - Rails 设计身份验证,外部应用程序请求被阻止

ruby-on-rails - Rails - 每个请求的数据库连接,基于用户凭据

jquery - 结合 Rails 和 jQuery、CSS?

ruby-on-rails - 如何使用 mongoid 构建管理 UI?

asp.net-mvc - Azure VM NGINX Plus + Web 应用程序导致 404