PmWiki Clean URLs on nginx

Building on yesterday’s post on setting up PmWiki on nginx, I figured out the nginx configurations for PmWiki Clean URLs.

First, copy the example config.php out of the docs/ directory to the root of the PMWiki site, in my case, I installed to $DOCROOT/pmwiki/:

cp pmwiki/docs/sample-config.php pmwiki/config.php

Following the Clean URL notes, in pmwiki/config.php I set:

$EnablePathInfo = 1;

then I hit the wiki front page and started to look at the resulting link URLs like – they all 404 at this point, but this gives an idea of what I want to do next. I want to get rid of the /index.php/ bit, first, so in pmwiki/config.php I set:

$ScriptUrl = '';

This worked – the resulting URLs are like – but, let’s make that a little more portable for other vhost names or aliases and set it to:

$ScriptUrl = 'http://'.$_SERVER['HTTP_HOST'].'/pmwiki';

This works perfectly – now to take care of all the 404s with nginx rewrites. From yesterday’s config, I added the “location /pmwiki” and “location @pmwiki” blocks – here’s my complete nginx server configuration:

server {
  listen 80;
  charset utf-8;
  access_log /var/log/nginx/wiki.access.log;
  root /var/www/wiki;
  index index.html index.php;

  location /pmwiki {
    error_page 404 = @pmwiki;
    log_not_found off;

  location @pmwiki {
    rewrite ^/pmwiki/(.*)$ /pmwiki/?n=$1 last;

  # configs from pmwiki .htaccess files
  location ~ ^/pmwiki/(cookbook|local|scripts|wiki.d|wikilib.d) {
    deny all;
  location ^~ /pmwiki/docs {
    autoindex on;
    types {
      text/plain php;

  # pass PHP scripts to FastCGI server listening on
  location ~ \.php$ {
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include /etc/nginx/fastcgi_params;

  # deny access to all .dot-files
  location ~ /\. {
    deny all;

If PmWiki is installed in the document root of the site (not under http://…/pmwiki/), then adjust the ScriptUrl in config.php:

$ScriptUrl = 'http://'.$_SERVER['HTTP_HOST']'';

and the nginx config blocks above to:

  location / {...}

  location @pmwiki {
    rewrite ^/(.*)$ /?n=$1 last;

  location ~ ^/(cookbook|local|scripts|wiki.d|wikilib.d) {...}

  location ^~ /docs {...}

2 thoughts on “PmWiki Clean URLs on nginx”

  1. Thanks for this nginx configuration info. It got me pointed in the right direction, but there’s a problem with your rewrites when pmwiki is at the root level that tripped me up for quite a while. The following rewrite works except in the case of the base URL (about to check if creating an index.php will resolve that): rewrite ^/(.*)$ /pmwiki.php?n=$1

  2. This, and your previous PmWiki/nginx post, are an excellent quickstart to getting PmWiki running in a clean fashion on nginx. Thanks a lot.

    Two things:

    1. config.php lives in /local not / (wiki root). So you want

    cp pmwiki/docs/sample-config.php pmwiki/local/config.php

    2. /docs can be deleted after installation. So, I just added it to the deny all list:

    # configs from pmwiki .htaccess files
    location ~ ^/(cookbook|docs|local|scripts|wiki.d|wikilib.d) {
    deny all;

    Thanks again for saving me a lot of time.

Comments are closed.