Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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...

share|improve this question
    
can you paste your vhost file for your domain –  anthonysomerset Jun 17 '11 at 10:14
add comment

2 Answers

up vote 4 down vote accepted

You have expires max; in your http section and this sets Expires header to 31 December 2037 23:59:59 GMT, and the Cache-Control max-age to 10 years.

share|improve this answer
    
Same comment here AlexD. Thanks for the tip, but again, don't know what to do to set it the right way to always show the last content, without the caching :( –  javipas Jun 17 '11 at 17:19
add comment

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.

share|improve this answer
    
Thanks Mike. But I'm affraid I've read the official docs and don't know for sure what to do with that. Do I delete this line, or just change it to "expires off"? –  javipas Jun 17 '11 at 17:18
    
Just delete this line or set it to something low, like few minutes. –  AlexD Jun 17 '11 at 17:20
    
do what alexd said.. i'd delete it if you want no cache at all –  Mike Jun 17 '11 at 17:34
    
Thx, I'll try the delete method and see what happens... But there's another question: do i have to remove also the "expires 30d" on the second file, the one for my site under /etc/nginx/sites-enabled? –  javipas Jun 17 '11 at 18:10
    
if you do not want to cache css, javascript or images.. yes –  Mike Jun 17 '11 at 19:54
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.