Nginx CSS 缓存

Nginx CSS 缓存

我已经尝试修复此问题一段时间了,但一直没能找到解决方案。

关于我的设置的一些说明:

  • 我没有使用 VirtualBox
  • 我正在运行 Nginx 1.4.6 Ubuntu

即使在我的网站配置中使用“expires: off;”标志,CSS 的缓存也不会清除。这是我的网站配置:

server {
  # Replace this port with the right one for your requirements
  listen 80;  #could also be 1.2.3.4:80

  # Multiple hostnames separated by spaces.  Replace these as well.
  server_name www.example.com; # Alternately: _

  root /var/www/;

  error_page 404 /404.html;

  location = /404.html {  
    root  /etc/nginx/errors;  
  }  
  #access_log logs/star.example.com.access.log;

  index index.php index.html index.htm;

  location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ {
    access_log off;
    expires off;
  }

  location / {
    root /var/www;
    try_files $uri $uri/ @extensionless-php;
    index index.php index.html;
  }

  location ~ \.php$ {
    include fastcgi_params;
    fastcgi_intercept_errors on;
    # By all means use a different server for the fcgi processes if you need to
    fastcgi_pass unix:/var/run/php5-fpm.sock;
  }

  location ~ /\.ht {
    deny  all;
  }

  location @extensionless-php {
    rewrite ^(.*)$ $1.php last;
  }

}

我的nginx.conf如下:

user www-data;
worker_processes 4;
pid /run/nginx.pid;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    client_max_body_size 150m;

    sendfile off;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 2;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # nginx-naxsi config
    ##
    # Uncomment it if you installed nginx-naxsi
    ##

    #include /etc/nginx/naxsi_core.rules;

    ##
    # nginx-passenger config
    ##
    # Uncomment it if you installed nginx-passenger
    ##

    #passenger_root /usr;
    #passenger_ruby /usr/bin/ruby;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

谢谢 :)

答案1

我认为expires off这不是您真正想要的。这只是完全禁用发送Cache-ControlExpires标头,并且您获得浏览器默认行为(通常符合 RFC,导致资源被缓存)。

如果您希望用户代理根本不缓存资源,请使用expires epoch

相关内容