Upgrading to Nginx and getting WordPress to work

So, after doing an upgrade of my Apache installation all my web content stopped working. It continued to give 403 errors. After spending hours changing permissions and checking every little detail I gave up. So I installed Nginx instead. It’s a bit scary to start using a totally new web server software, but why not live dangerously? Anyway, it’s fast! Really fast. The only problem I had was to get all the redirects to work. And I also removed my gallery2 installation and moved the blog to /

Problems

It took longer than I had anticipated, mainly because I had to learn how to set up Nginx, but also because of the trouble of getting answers when searching the net. But here’s my working config (mostly saved for me if I forget :)

[cc lang="apache"]
server {
    listen   80;
    servername  www.jackenhack.com
            jackenhack.com;
    keepalivetimeout  5;
    tcp_nodelay        on;  

access_log  /var/log/nginx/access.log;

location ~* ^.+.(xml|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$ { root /var/www/nginx-default;

}

location / {
    root   /var/www/nginx-default;
    index  index.php index.html index.htm;

gzip on; gziphttpversion 1.0; gzipcomplevel 2; gzipproxied any; gziptypes text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;

#include /etc/nginx/wordpress_params.super_cache
#include /etc/nginx/enable_wordpress;

# rewrite old blog url
rewrite ^/blog/(.+)$ /$1 permanent;

if the requested file exists, return it immediately

if (-f $request_filename) { break; }

set $supercachefile ''; set $supercacheuri $request_uri;

if ($requestmethod = POST) { set $supercacheuri ''; }

Using pretty permalinks, so bypass the cache for any query string

if ($querystring) { set $supercacheuri ''; }

if ($httpcookie ~* "commentauthor|wordpress|wp-postpass" ) { set $supercache_uri ''; }

if we haven't bypassed the cache, specify our supercache file

if ($supercacheuri ~ ^(.+)$) { set $supercachefile /wp-content/cache/supercache/$http_host/$1index.html; }

only rewrite to the supercache file if it actually exists

if (-f $documentroot$supercachefile) { rewrite ^(.*)$ $supercache_file break; }

all other requests go to WordPress

if (!-e $request_filename) { rewrite . /index.php last; }

}

setup for jackeniax

    location /jackeniax {
        root   /var/www/nginx-default/jackeniax;
        index  index.php index.html;

        if (!-f $request_filename) {
            rewrite  ^(.*)$  /jackeniax/index.php?q=$1  last;
            break;
        }

        if (!-d $request_filename) {
            rewrite  ^(.*)$  /jackeniax/index.php?q=$1  last;
            break;
        }

    }

    location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /var/www/nginx-default$fastcgi_script_name;
            include        /etc/nginx/fastcgi_params;
    }

# deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
            deny  all;
    }

} [/cc]