在Debian Wheezy Web Server上禁用文件缓存

时间:2015-04-28 02:10:09

标签: linux apache caching nginx debian

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

上传和显示我的文件不是问题。但是,如果更新或删除文件,则Web服务器仍会提供上载文件的陈旧信息,或者提供已从硬盘驱动器中删除的文件。

我已经尝试了Nginx和Apache2,问题仍然存在,所以也许它是Debian本身的某种形式的缓存?

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

VHost配置,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;
        #}
}

1 个答案:

答案 0 :(得分:1)

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

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

并使用nginx -s reload

重新启动nginx

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