DokuWiki Pseudo-Static Configuration for Nginx

Publish: 2016-01-15 | Modify: 2016-01-15

DokuWiki is an open-source wiki engine program that runs on PHP. DokuWiki is small, powerful, and flexible, making it suitable for managing knowledge bases for small teams and personal websites. I recently started using this program, and it is very simple and convenient. For SEO purposes, the first step is usually to set up pseudo-static pages. So how do you set up DokuWiki on the Nginx web server?

Below is my personal Nginx vhost configuration file, which can be added to the Nginx rewrite rules for reference:

server {
    listen 80;
    server_name zhuji.wiki www.zhuji.wiki;
    access_log /data/wwwlogs/zhuji.wiki_nginx.log combined;
    index index.html index.php duku.php;
    include /usr/local/nginx/conf/none.conf;
    root /data/wwwroot/zhuji.wiki;

    location / { try_files $uri $uri/ @dokuwiki; }

    location @dokuwiki {
        rewrite ^/_media/(.*) /lib/exe/fetch.php?media=$1 last;
        rewrite ^/_detail/(.*) /lib/exe/detail.php?media=$1 last;
        rewrite ^/_export/([^/]+)/(.*) /doku.php?do=export_$1&id=$2 last;
        rewrite ^/(?!lib/)(.*) /doku.php?id=$1&$args last;
    }

    location ~ [^/]\.php(/|$) {
        #fastcgi_pass remote_php_ip:9000;
        fastcgi_pass unix:/dev/shm/php-cgi.sock;
        fastcgi_index index.php;
        include fastcgi.conf;
    }

    location ~ .*\.(js|css)?$ {
        expires 7d;
        access_log off;
    }
}

The core rules that need to be added within the server block are as follows:

location / { try_files $uri $uri/ @dokuwiki; }

location @dokuwiki {
    rewrite ^/_media/(.*) /lib/exe/fetch.php?media=$1 last;
    rewrite ^/_detail/(.*) /lib/exe/detail.php?media=$1 last;
    rewrite ^/_export/([^/]+)/(.*) /doku.php?do=export_$1&id=$2 last;
    rewrite ^/(?!lib/)(.*) /doku.php?id=$1&$args last;
}

location ~ .*\.(js|css)?$ {
    expires 7d;
    access_log off;
}

Next, add the following line to the conf/local.php file:

$conf['userewrite'] = 2;

Finally, modify the DokuWiki backend settings: Backend -> Administration -> Configuration Settings -> Advanced Settings -> Use cleaner URLs. Check the .htaccess file to see the effect.

For more detailed rules, please refer to the official documentation: DokuWiki Rewrite.

dokuwiki_626_149

For detailed rules, please refer to the official documentation: DokuWiki Rewrite.


Comments