Nginxcaching网页? 用户必须每次刷新以查看家庭和文章的更新

我们在使用Nginx + MySQL + PHP-FPM(以及WordPress作为CMS)的大多数服务器上遇到问题:浏览器不显示我们网页的最新版本。

我会这样解释:

  • 首页显示罚款第一次我们的访问者加载它。
  • 我们添加新的文章和内容,并从Wordpress发布。
  • 当用户再次加载房屋时,他看到的是与之前看到的完全相同的页面,没有改变。
  • 他必须重新加载主页(Ctrl + F5,Command + r)才能看到家中的新文章和内容。

但是在我们的一台服务器中,更糟糕的是,有些用户必须在浏览器上清理caching(例如Internet Explorer,显示出严重的问题),然后他们才能看到新的文章最终发布。

当用户在post上添加新评论时也会发生同样的情况:除非他刷新网页,否则不会显示该评论。 一切似乎caching,但我不知道为什么。

我在这些博客上没有在wordpress中使用任何caching插件,所以这可能发生的唯一原因是在Nginx中configuration不当。

根据要求,这里有两个“重要”文件:

/etc/nginx/nginx.conf user www-data; worker_processes 4; error_log /var/log/nginx/error.log; pid /var/run/nginx.pid; events { worker_connections 4096; use epoll; multi_accept on; accept_mutex_delay 50ms; } http { include /etc/nginx/mime.types; access_log /var/log/nginx/access.log; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; tcp_nodelay on; expires max; server_tokens off; gzip on; gzip_static on; gzip_proxied any; gzip_types text/plain text/css application/x-javascript text/xml text/javascript application/xml; gzip_vary on; gzip_disable "MSIE [1-6]\.(?!.*SV1)"; include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; } 

和/etc/nginx/sites-enabled/mysite.com

 server { listen 80; server_name mysite.com *.mysite.com; rewrite ^/(.*) http://www.mysite.com/$1 permanent; } server { listen 80; # access_log /var/www/mysite/log/access.log; # error_log /var/www/mysite/log/error.log info; server_name www.mysite.com; root /var/www/mysite/; location / { index index.php; try_files $uri $uri/ /index.php?q=$uri&$args; # if the requested file exists, return it immediately if (-f $request_filename) { break; } # all other requests go to WordPress if (!-e $request_filename) { rewrite . /index.php last; } } ## Images and static content is treated different location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ { access_log off; expires 30d; root /var/www/mysite/; } ## Parse all .php file in the /var/www directory location ~ .php$ { fastcgi_split_path_info ^(.+\.php)(.*)$; fastcgi_pass backend; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/mysite/$fastcgi_script_name; include fastcgi_params; fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_intercept_errors on; fastcgi_ignore_client_abort on; fastcgi_read_timeout 180; } ## Disable viewing .htaccess & .htpassword location ~ /\.ht { deny all; } } upstream backend { server 127.0.0.1:9000; } } 

希望有帮助…

您已经expires max; 在你的http部分中,这将Expires头设置为2037年12月31日23:59:59 GMT,并将Cache-Control max-age为10年。

全球你有一个过期最大; 在你的http {}中设置

http://wiki.nginx.org/HttpHeadersModule

这可能是什么告诉浏览器没有新的数据在页面加载,除非他们刷新。