Twentyeleven theme in WordPress - Nginx as reverse proxy to Apache2

There are many attractions of Nginx as a front-end to Apache for
WordPress -
not least the retention of permalink facilities.

I have been trying this for some time now and, when it works, the
performance is certainly excellent. However there is one problem with
all
the configurations I have been trying and that is the header image in
the
default WordPress twentyeleven theme when not logged in.

This should load a random image on each refresh but, even though the
image
name should change, the same image is always reloaded.

The platform is Ubuntu 10.04 LTS, nginx 1.2.3 stable, Apache/2.2.14
(Ubuntu), WordPress 3.4.2.

Here is the essential bit from nginx.conf in my current tests:

=============================================================================
proxy_cache_path /var/lib/nginx/cache levels=1:2
keys_zone=staticfilecache:180m max_size=100m;
proxy_temp_path /var/lib/nginx/proxy;
proxy_connect_timeout 30;
proxy_read_timeout 120;
proxy_send_timeout 120;

#IMPORTANT - this sets the basic cache key that’s used in the static
file
cache.
proxy_cache_key “$scheme://$host$request_uri”;

… and the essentail /etc/nginx/conf.d/wordpress.conf file which is
included in every server {} definition:

=============================================================================
# Set the real IP.
proxy_set_header X-Real-IP $remote_addr;

    # Set the hostname
    proxy_set_header Host $host;

    #Set the forwarded-for header.
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    # Let the Set-Cookie header through.
    proxy_pass_header Set-Cookie;

    location / {

                    # If logged in, don't cache.
                    if ($http_cookie ~*

“comment_author_|wordpress_(?!test_cookie)|wp-postpass_” ) {
set $do_not_cache 1;
}
proxy_cache_key “$scheme://$host$request_uri
$do_not_cache”;
proxy_cache staticfilecache;
proxy_pass http://apache;
}

    location ~* wp\-.*\.php|wp\-admin {
                    # Don't static file cache admin-looking things.
                    proxy_pass http://apache;
    }

    location ~*

.(jpg|png|gif|jpeg|css|js|mp3|wav|swf|mov|doc|pdf|xls|ppt|docx|pptx|xlsx)$
{
# Cache static-looking files for 120 minutes,
setting a 10 day expiry time in the HTTP header,
# whether logged in or not (may be too
heavy-handed).
proxy_cache_valid 200 120m;
expires 864000;
proxy_pass http://apache;
proxy_cache staticfilecache;
}

    location ~* \/[^\/]+\/(feed|\.xml)\/? {
                    # Cache RSS looking feeds for 45 minutes unless

logged in.
if ($http_cookie ~*
“comment_author_|wordpress_(?!test_cookie)|wp-postpass_” ) {
set $do_not_cache 1;
}
proxy_cache_key “$scheme://$host$request_uri
$do_not_cache”;
proxy_cache_valid 200 45m;
proxy_cache staticfilecache;
proxy_pass http://apache;
}

    location = /50x.html {
            root   /var/www/nginx-default;
    }

    # No access to .htaccess files.
    location ~ /\.ht {
            deny  all;
    }

=============================================================================

So clearly WordPress is not being asked to provide a new header.
Clearly I
can make it do so by setting expires 0 but that rather defeats the
purpose
of having nginx up front.

Any ideas?

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,230916,230916#msg-230916

Actually it’s more serious than just the image. If you add a new
comment
when not logged in, the whole post with the new comment is entered into
the
cache and served OK. But an immediate additional comment added is not
served because the cache hasn’t expired. The comment count is also not
updated.

I have tried adding the Nginx proxy cache integrator which adds
effectively
expires the cache where particular types of cookie are found but a
visitor
does not (in general) result in a cookie so the image problem at least
remains.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,230916,230919#msg-230919

The comment issue remains even with the WordPress Nginx proxy cache
integrator plugin activated and the comments approved. They are not
visible
until the page of posts has expired.:frowning:

The plugin sets X-Accel-Expires to 0 where wordpress_comment_author or
wordpress_wp-postpass cookies are set, thus switching off caching for
that
page and renewing the cache copy.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,230916,230920#msg-230920

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs