Welcome! Log In Create A New Profile

Advanced

twentyeleven theme in WordPress - Nginx as reverse proxy to Apache2

September 21, 2012 06:42AM
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?
Subject Author Posted

twentyeleven theme in WordPress - Nginx as reverse proxy to Apache2

Loggy September 21, 2012 06:42AM

Re: twentyeleven theme in WordPress - Nginx as reverse proxy to Apache2

Loggy September 21, 2012 08:37AM

Re: twentyeleven theme in WordPress - Nginx as reverse proxy to Apache2

Loggy September 21, 2012 08:59AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 181
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready