Home > web > Upgrading to Nginx and getting WordPress to work

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 :)

server {
    listen   80;
    server_name  www.jackenhack.com
            jackenhack.com;
    keepalive_timeout  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;
  gzip_http_version 1.0;
  gzip_comp_level 2;
  gzip_proxied any;
  gzip_types      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 $supercache_file '';
set $supercache_uri $request_uri;

if ($request_method = POST) {
set $supercache_uri '';
}

# Using pretty permalinks, so bypass the cache for any query string
if ($query_string) {
set $supercache_uri '';
}

if ($http_cookie ~* "comment_author_|wordpress|wp-postpass_" ) {
set $supercache_uri '';
}

# if we haven't bypassed the cache, specify our supercache file
if ($supercache_uri ~ ^(.+)$) {
set $supercache_file /wp-content/cache/supercache/$http_host/$1index.html;
}

# only rewrite to the supercache file if it actually exists
if (-f $document_root$supercache_file) {
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;
        }

}

Categories: web Tags: , , ,
  1. Peter Olsson
    June 25th, 2009 at 04:50 | #1

    Fantastic Jacken, but I have a PC… :(

  2. Jacken
    June 25th, 2009 at 08:10 | #2

    This is for PC, just format and resinstall with Linux and your good to go..

  1. No trackbacks yet.