WordPress fastcgi cache warmup

In order to reduce the loadup times for my blog I have created a cache warmup script. The script parses the wordpress sitemap and calls all urls via curl. The sitemap is created by Google Sitemap Generator Plugin and contains all urls.

#!/bin/bash
# wp_warmup.sh

cat /var/www/wordpress/sitemap.xml | grep loc | awk -F "<loc>" '{ print $2 }' | awk -F "</loc>" '{ print $1 }'  | sort | uniq | xargs curl -A warmup -silent  >/dev/null

The script is called by this crontab entry every hour:

# m h  dom mon dow   command
0 * * * * /usr/local/bin/wp_warmup.sh

Nginx (based on this config) has to be configured accordingly

fastcgi_cache_valid      200 302 59m;

This combunation works very well. My google response time statistic looks much better now. Google and other search engines use the resposne time for their ranking. This setup will ensure that my website is always fast for the search engines.

Nginx 1.3.12 GeoIP IPv6

Since release 1.3.12 the geoip module supports IPv6. This nginx configuration works fine for me:

geoip_country   /usr/share/GeoIP/GeoIPv6.dat; # the country IP database
geoip_city      /usr/share/GeoIP/GeoLiteCityv6.dat; # the city IP database

I use $geoip_country_code in my logformat in order to log the country:

log_format  main  '$host $remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for" '
                  '$ssl_cipher $request_time $gzip_ratio '
                  '$upstream_addr $upstream_response_time $geoip_country_code';

A quick test shows eveything is working as designed:

user@aladin:/home/phil# curl -I -4  http://www.hellmi.de
HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Sun, 10 Feb 2013 10:48:07 GMT
Content-Type: text/html
Content-Length: 178
Connection: keep-alive
Location: https://www.hellmi.de/en/

user@aladin:/home/phil# curl -I -6  http://www.hellmi.de
HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Sun, 10 Feb 2013 10:48:12 GMT
Content-Type: text/html
Content-Length: 178
Connection: keep-alive
Location: https://www.hellmi.de/en/

user@aladin:/home/phil# tail -2 /var/log/nginx/access.log
www.hellmi.de 66.228.57.159 - - [10/Feb/2013:10:48:07 +0000] "HEAD / HTTP/1.1" 301 0 "-" "curl/7.22.0 (i686-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3" "-" - 0.000 - - - US
www.hellmi.de 2600:3c02::f03c:91ff:fe96:b43f - - [10/Feb/2013:10:48:12 +0000] "HEAD / HTTP/1.1" 301 0 "-" "curl/7.22.0 (i686-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3" "-" - 0.000 - - - US

The IPv6 database contains IPv4 addresses as well, thus resolving both types work using the same configuration.

WordPress auto language detection with nginx

My blog uses the “Stella plugin free” wordpress plugin. Unfortunately this plugin doesn’t support auto language detection in the free version. But nginx has a plugin for language detection which can do the job as well. This is my sample configuration which works fine.

server {
    listen 80;
    listen [::]:80;

    server_name hellmi.de www6.hellmi.de www.hellmi.de;

    set_from_accept_language $lang en de;

    location / {
        rewrite ^/(.*) /$lang/$1;
    }

    location = /en {
        rewrite ^ /en/;
    }
    location /en/ {
        rewrite ^/en/(.*) https://www.hellmi.de/en/$1 permanent;
    }

    location = /de {
        rewrite ^ /de/;
    }
    location /de/ {
        rewrite ^/de/(.*) https://www.hellmi.de/$1 permanent;
    }     
}

The nginx module can be found here: nginx_accept_language_module

Balboa Beach

Wikipedia

Grand Canyon

Grand Canyon

Grand Canyon