Search code examples
cachingnginxvagrantvirtualboxfastcgi

nginx + php5-fpm + wordpress caching


I've got some very aggressive caching happening (from what I can tell) with my setup.

To eliminate possible browser caching, I'm requesting a CSS file using curl:

$ curl http://localhost:8080/wp-content/plugins/zip-recipes/plugins/VisitorRating/styles/css-stars.css?ver=4.3.1
.br-theme-css-stars .br-widget {
  height: 28px;
}
.br-theme-css-stars .br-widget a {
  text-decoration: none;
  height: 18px;
  width: 18px;
  float: left;
  font-size: 23px;
  margin-right: 2px;
}
.br-theme-css-stars .br-widget a:after {
  content: "\2605";
  position: absolute;
  color: #dddddd;
}
.br-theme-css-stars .br-widget a.br-active:after {
  color: #ffdf88;
}
.br-theme-css-stars .br-widget a.br-selected:after {
  color: #ffdf88;
}
.br-theme-css-stars .br-widget .br-current-rating {
  display: none;
}

From the server, looking at /var/log/nginx/access.log, I can see that the file is being requested:

10.0.2.2 - - [22/Nov/2015:07:51:02 +0000] "GET /wp-content/plugins/zip-recipes/plugins/VisitorRating/styles/css-stars.css?ver=4.3.1 HTTP/1.1" 200 517 "-" "curl/7.43.0"

Then I cat the file in the server:

$ cat /wordpress_env/wp-content/plugins/zip-recipes/plugins/VisitorRating/styles/css-stars.css
.br-theme-css-stars .br-widget {
  height: 28px;
}
.br-theme-css-stars .br-widget a {
  text-decoration: none;
  height: 18px;
  width: 18px;
  float: left;
  font-size: 23px;
  margin-right: 2px;
}
.br-theme-css-stars .br-widget a:after {
  content: "\2605";
  position: absolute;
  color: #dddddd;
}
.br-theme-css-stars .br-widget a.br-active:after {
  color: #ffdf88;
}
.br-theme-css-stars .br-widget a.br-selected:after {
  color: #CE0B15;
}
.br-theme-css-stars .br-widget .br-current-rating {
  display: none;
}

Note, the last color: is different than what's being returned to the browser.

I'm not sure what's caching this but I need it to stop :)

Update: Here's the nginx config file:

$ cat /etc/nginx/sites-enabled/wordpress 
server {
        listen   8080;


        root /wordpress_env;
        index index.php index.html index.htm;

        location / {
        expires -1;
                try_files $uri $uri/ /index.php?q=$uri&$args;
        }

        error_page 404 /404.html;

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
              root /usr/share/nginx/www;
        }

        location ~ \.php$ {
                try_files $uri =404;
                # With php5-fpm:
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
                 }


}

Solution

  • The environment that I'm running my server in is a VirtualBox machine using vagrant.

    It turns out this has everything to do with it because VirtualBox hates sendfile.

    The solution was to modify /etc/nginx/nginx.conf and turn sendfile off:

    http {
    
            ##
            # Basic Settings
            ##
    
            sendfile off;
            ...
    }
    

    Thanks to ServerFault for the answer.