添加最后修改的标头后,客户端不会加载资产

时间:2012-07-18 12:00:50

标签: ruby-on-rails nginx thin last-modified

我在Debian上使用thin和nginx(0.7.6)在生产模式下运行我的rails应用程序。它工作得很好但不是我试图实现最后修改的头,当我重新启动nginx时,客户端不再加载资产。

这是我的nginx配置:

upstream instance-name {
        server unix:/var/run/thin/appname.0.sock;
        server unix:/var/run/thin/appname.1.sock;
        server unix:/var/run/thin/appname.2.sock;
        server unix:/var/run/thin/appname.3.sock;
}

server {
        listen 5678;
        server_name appname;
        access_log /root/rails/appname/log/access.log;
        error_log /root/rails/appname/log/error.log;
        root /root/rails/appname/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://fibre-dox;
                        break;
                }
        }
        location ~* \.(jpg|gif|png|css|js)$ {
               if (-f $request_filename) {
                       expires max;
                       break;
               }
        }
}

导致我麻烦的部分是这个:

location ~* \.(jpg|gif|png|css|js)$ {
                   if (-f $request_filename) {
                           expires max;
                           break;
                   }
            }

我做错了什么?我想使用最后修改过的标题,这样客户端每次点击页面时都不会重新加载所有图片。

1 个答案:

答案 0 :(得分:0)

    location / {
            try_files $uri $uri/ $uri.html @backend;

            location ~* \.(?:jpg|gif|png|css|js)$ {
                try_files $uri @backend;
                expires max;
            }
    }

    location @backend {
            proxy_pass http://fibre-dox;
            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;

            location ~* \.(?:jpg|gif|png|css|js)$ {
                proxy_pass http://fibre-dox;
                expires max;
            }
    }