we are having a problem with most of our servers with Nginx +MySQL+PHP-FPM (and WordPress as the CMS): browsers don't show last versions of our webpages.
I'll explain it this way:
- The homepage shows fine the first time our visitors load it.
- We add new articles and content, and publish it from Wordpress.
- When a user loads again the home, he sees exactly the same page he saw before, without changes.
- He has to reload the homepage (Ctrl+F5, Command+r) in order to see the new articles and content on the home.
But it is even worse in one of our servers, where some users must clean caches on their browsers (Internet Explorer, for example, shows a serious problem), and then they can see the new home with new articles finally published.
The same happens when a user adds a new comment on a post: the comment doesn't show unless he refreshes the webpage. Everything seems to be caching, but I don't know exactly why.
I don't use any cache plugin in wordpress on these blogs, so the only reason this could be happening is a bad configuration in Nginx.
As requested, here are the two "important" files here:
/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/*;
}
And /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;
}
}
Hope that helps...
You have
expires max;
in yourhttp
section and this setsExpires
header to 31 December 2037 23:59:59 GMT, and theCache-Control max-age
to 10 years.globally you have an expires max; set in your http {}
http://wiki.nginx.org/HttpHeadersModule
This is probably what is telling browsers there is no new data on page load unless they refresh it.