# Twentyeleven theme in WordPress - Nginx as reverse proxy to Apache2

**URL:** <https://www.ruby-forum.com/t/twentyeleven-theme-in-wordpress-nginx-as-reverse-proxy-to-apache2/223092>\
**Category:** NGINX\
**Created:** [September 21, 2012, 12:42pm UTC](https://www.ruby-forum.com/t/twentyeleven-theme-in-wordpress-nginx-as-reverse-proxy-to-apache2/223092 "2012-09-21T12:42:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [September 21, 2012, 12:42pm UTC](https://www.ruby-forum.com/t/twentyeleven-theme-in-wordpress-nginx-as-reverse-proxy-to-apache2/223092/1 "2012-09-21T12:42:57Z")

</div>

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](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](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](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:

> **[twentyeleven theme in WordPress - Nginx as reverse proxy to Apache2](https://forum.nginx.org/read.php?2,230916,230916#msg-230916)**
>
> 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...

---

<div class="post-metadata">

**Author:** ![loggy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/a88e57/32.png) [@loggy](https://www.ruby-forum.com/u/loggy)\
**Post date:** [September 21, 2012, 2:38pm UTC](https://www.ruby-forum.com/t/twentyeleven-theme-in-wordpress-nginx-as-reverse-proxy-to-apache2/223092/2 "2012-09-21T14:38:04Z")

</div>

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:

> **[Re: twentyeleven theme in WordPress - Nginx as reverse proxy to Apache2](https://forum.nginx.org/read.php?2,230916,230919#msg-230919)**
>
> 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...

---

<div class="post-metadata">

**Author:** ![loggy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/a88e57/32.png) [@loggy](https://www.ruby-forum.com/u/loggy)\
**Post date:** [September 21, 2012, 2:59pm UTC](https://www.ruby-forum.com/t/twentyeleven-theme-in-wordpress-nginx-as-reverse-proxy-to-apache2/223092/3 "2012-09-21T14:59:42Z")

</div>

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

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:

> **[Re: twentyeleven theme in WordPress - Nginx as reverse proxy to Apache2](https://forum.nginx.org/read.php?2,230916,230920#msg-230920)**
>
> 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...
