【问题标题】:Disable file caching on Debian Wheezy Web Server在 Debian Wheezy Web 服务器上禁用文件缓存
【发布时间】:2015-07-06 16:39:57
【问题描述】:

我有一个 Debian Wheezy 服务器,我正在其上运行一个 Web 服务器。我的 Web 根目录下有一个名为 data 的文件夹,其中包含几个不经常更新的 json 文件。

上传和显示我的文件不是问题。但是,如果文件被更新或删除,网络服务器仍会提供已上传文件的过时信息,或提供已从硬盘驱动器物理删除的文件。

我已经尝试过 Nginx 和 Apache2,但问题仍然存在,所以可能是 Debian 本身的某种形式的缓存?

有没有办法只显示我的data 目录中的当前内容而不缓存文件?

虚拟主机配置,nginx

server {
        root /var/www;
        index index.html index.htm;

        server_name localhost;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ /index.html;
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rules
        }

        location /doc/ {
                alias /usr/share/doc/;
                autoindex on;
                allow 127.0.0.1;
                allow ::1;
                deny all;
        }

        # Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
        #location /RequestDenied {
        #       proxy_pass http://127.0.0.1:8080;
        #}

        #error_page 404 /404.html;

        # redirect server error pages to the static page /50x.html
        #
        #error_page 500 502 503 504 /50x.html;
        #location = /50x.html {
        #       root /usr/share/nginx/www;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #       fastcgi_split_path_info ^(.+\.php)(/.+)$;
        #       # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
        #
        #       # With php5-cgi alone:
        #       fastcgi_pass 127.0.0.1:9000;
        #       # With php5-fpm:
        #       fastcgi_pass unix:/var/run/php5-fpm.sock;
        #       fastcgi_index index.php;
        #       include fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #       deny all;
        #}
}

【问题讨论】:

  • 能否请您包含网络服务器配置?
  • @John 你能说得更具体点吗?虚拟主机配置?还是服务器本身的配置?两者都比较长。是否有我应该寻找的特定参数?
  • 对不起,我指的是虚拟主机配置,当然..
  • @John 在我的 nginx 服务器上更新了我的站点的 vhost 文件

标签: linux apache caching nginx debian


【解决方案1】:

尝试将以下内容添加到您的服务器块

location ~* \.(?:json)$ {
   expires -1;
}

然后使用nginx -s reload重启nginx

这应该禁用所有 .json 文件的缓存

【讨论】:

  • 在尝试您的代码块时收到错误 [emerg] unexpected "}"
  • 哈,是的,我应该自己抓住它……无论如何,它就像一个魅力!非常感谢,老兄。
  • 其实还是有stale数据,已经删除的文件已经无法访问了,但是好像还在缓存live文件?
  • 事实证明它现在更新得更快,不到一分钟。我没关系
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-05-12
  • 1970-01-01
  • 1970-01-01
  • 2020-10-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多