It's better when it's simple

User Tools

Site Tools


Translations of this page?:

Learn about DokuWiki

Advanced Use

Corporate Use

Our Community

Follow us on Facebook, Twitter and other social networks.

Our Privacy Policy



DokuWiki with nginx on Ubuntu

You need to install nginx and php-fpm, if you are on a current release, this will be at least php7.0.

The nginx config below is based mostly on the sample configuration in this site here updated to work with current relases (tested with 16.04 LTS). With the image caching config from this site

On the initial setup you won't be able to start unless you comment the deny to the install.php file This is the full configuration we use you can simply copy paste and change the names to your liking. please be aware this is running as a vhost. You'll likely need to put it in /etc/nginx/sites-enabled by default (or somewhere else if you've changed the configuration)

Note this is https, so you will either need a certificate or use a self-signed certificate to configure this way. The configuration for the https certificate is typical like this (to get a good security rating):

# file with the cert + intermediates
ssl_certificate /etc/ssl/certs/example_com_pack.crt;
ssl_certificate_key /etc/ssl/private/example_com.key;
ssl_session_timeout 5m;
ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES";
# Use 2048 bit Diffie-Hellman RSA key parameters
# (otherwise Nginx defaults to 1024 bit, lowering the strength of encryption # when using PFS)
# Generated by OpenSSL with the following command:
# openssl dhparam -outform pem -out /etc/nginx/ssl/dhparam2048.pem 2048
ssl_dhparam /etc/ssl/private/dhparam2048.pem;
server {
    listen               80;
    listen                   [::]:80;
    server_name          wiki.domain.example;
    return 301 https://$server_name$request_uri;
server {
    listen [::]:443 ssl;
    listen 443 ssl;
    server_name wiki.domain.example;
    # Maximum file upload size is 4MB - change accordingly if needed
    client_max_body_size 4M;
    client_body_buffer_size 128k;
    root /dokuwiki;
    index doku.php;
    #Remember to comment the below out when you're installing, and uncomment it when done.
    location ~ /(data/|conf/|bin/|inc/|install.php) { deny all; }
    location ~ ^/lib.*\.(js|css|gif|png|ico|jpg|jpeg)$ {
        expires 365d;
    location / { try_files $uri $uri/ @dokuwiki; }
    location @dokuwiki {
        # rewrites "doku.php/" out of the URLs if you set the userwrite setting to .htaccess in dokuwiki config page
        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 ^/(.*) /doku.php?id=$1&$args last;
    location ~ \.php$ {
        try_files $uri $uri/ /doku.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param REDIRECT_STATUS 200;
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        # fastcgi_pass unix:/var/run/php5-fpm.sock; #old php version

Once this file has been placed you should restart nginx and php-fpm.

service php7.0-fpm reload && service nginx reload
# service php5-fpm reload && service nginx reload # for the older php5 version

If you get a 502 gateway issue, it usually means there is a problem with your phpfpm socket configuration (usually wrong path to the socket). Please see the docs for phpfpm and nginx.

DokuWiki with nginx on Windows

Dokuwiki has been extracted to E:\www\dokuwiki.

This is an example for dokuwiki entry in nginx.conf running on Windows:

location ~ ^/dokuwiki/.*\.php {
    root           E:/www;	         
    fastcgi_param  SCRIPT_FILENAME    E:/www$fastcgi_script_name;
    fastcgi_param  QUERY_STRING       $query_string;
    include        fastcgi_params;
# serve static files
location ~ ^/dokuwiki/lib/  {
    root         E:/www;		
    expires 30d;
location ~ ^/dokuwiki/conf/ { deny all; }
location ~ ^/dokuwiki/data/ { deny all; }
location ~ /\.ht            { deny all; }

FastCGI and nginx have been started using this batch file:

ECHO Starting PHP FastCGI...
RunHiddenConsole.exe E:\appl\php-5.2.9-2-Win32\php-cgi.exe -b
ECHO Starting nginx...
cd /d D:\nginx-0.8.39 && start nginx.exe

Or you could try Start-Nginx if you prefer a normal windows GUI.

Linux configuration for Debian 8

You need to have already installed nginx and php5-fpm.

Depending of your choices your php part in sites documents could be with socks or ports.

You just copy paste what's working for you.

This site configuration is without ssl and use URL rewrite

in that exemple dokuwiki is at the root of a domain called

As root :

create a new nginx site file :

nano /etc/nginx/sites-available/

you paste in the code below of course change the path to your doku wiki and change the server_name :

server {
      listen 80;
      root /var/www/;
      index index.php index.html doku.php;
      location ~ ^/(data|conf|bin|inc) {
              return 404;
      location ~ ^/lib.*\.(gif|png|ico|jpg)$ {
              expires 31d;
      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 ^/tag/(.*) /doku.php?id=tag:$1&do=showtag&tag=tag:$1 last;
              rewrite ^/(.*) /doku.php?id=$1&$args last;
	 # here you paste your location ~ \.php$ 
	 # here is mine commented
     # location ~ \.php$ {
     #         include /etc/nginx/fastcgi_params;
     #         fastcgi_param   SCRIPT_FILENAME  $document_root$fastcgi_script_name;
     #         fastcgi_pass unix:/var/run/php5-fpm.sock;
     # }

and make it enable and restart ngnix :

ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/
service nginx restart
install/nginx.txt · Last modified: 2018-10-29 13:08 by aseques