DokuWiki

It's better when it's simple

User Tools

Site Tools


Sidebar

Translations of this page?:

Learn about DokuWiki

Advanced Use

Corporate Use

Our Community


Follow us on Facebook, Twitter and other social networks.

install:nginx

nginx

DokuWiki with nginx on Ubuntu Linux 12.04 and newer

You need to install nginx and php5-fpm, on 12.10 and newer the php-fpm already starts as a socket, but on 12.04 it starts listening on port 9000. It needs to be listening on a socket for the following configuration to work correctly.

cat /etc/php5/fpm/pool.d/www.conf | grep listen

If it outputs the following then the configuration below is good, otherwise you may need to modify it.

listen = /var/run/php5-fpm.sock

The nginx config below is based mostly on the sample configuration in this site here. 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.

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; }

#   Uncomment this prevents images being displayed ! 
#    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
#        expires 31536000s;
#        add_header Pragma "public";
#        add_header Cache-Control "max-age=31536000, public, must-revalidate, proxy-revalidate";
#        log_not_found off;
#    }
 
    location / { try_files $uri $uri/ @dokuwiki; }
 
    location @dokuwiki {
        # rewrites for userewrite=1
        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/php5-fpm.sock;
    }
}

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

service php5-fpm reload && service nginx reload

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

Issue with image media

FIXME

Using the above setup on Debian 7.9 Wheezy (october 2015) with nice URLs activated leads to a situation where images show up in the media browser (and ckgedit editor) but not on the actual pages. It appears that files ending with .jpg are treated by the 2nd location block (dealing with long browser caching) and not the rewrite location block. Commenting out the caching location block makes images visible.

Inspired by this site here is an alternate long caching location block, limited to dokuwiki internal files:

location ~ ^/lib.*\.(js|css|gif|png|ico|jpg|jpeg)$ {
    expires 365d;
}

(I am a beginner regarding nginx so this should be checked.)

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_pass   127.0.0.1:9000;
    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 127.0.0.1:9000
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 older releases

FIXME Is this needed anymore?

This configuration was tested on Ubuntu versions between Ubuntu 10.04 and (X)Ubuntu 12.04. Make sure the following packages are installed: NOTE: Most of the current installs are based on php-fpm (see the above example), this one is left here for the record

  • nginx
  • php5-cgi

Edit /etc/nginx/nginx.conf:

user www-data www-data;
#(...)
 
http {
  #(...)
 
  server{
    #listen 80;
    index index.html index.php doku.php;
    #make sure a global root is defined here
    #root   /var/www/     #adapt please
 
    location ~ ^/dokuwiki/(data|conf|bin|inc)/ {   # secure DokuWiki
      deny all;
    }
    location ~ /\.ht            { deny all; } #Deny Access to htaccess-Files for Apache
 
    location ~ ^/dokuwiki/.*\.php$ {
      root           /usr/share/dokuwiki;    #adapt if needed     
      include        fastcgi_params;
      fastcgi_pass   unix:/tmp/php-fastcgi.socket;
      fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
      fastcgi_param  PATH_INFO        $uri;  #necessary for URL rewrite
    }
 
    # serve static files
    location ~ ^/dokuwiki/lib/^((?!php).)*$  {
      root         /usr/share/dokuwiki/lib;   #adapt if needed
      expires 30d;
    }
  }
}

To launch fastcgi, we create the file php-fastcgi.conf (sudo gedit /etc/init/php-fastcgi.conf) with the following content:

description "php-fastcgi - keep up php-fastcgi"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
exec /usr/bin/sudo -u www-data PHP_FCGI_CHILDREN=2 PHP_FCGI_MAX_REQUESTS=125 /usr/bin/php-cgi -q -b /tmp/php-fastcgi.socket

We can either reboot (→fastcgi and nginx should run automatically), or use the following commands for manual testing:

  • Start fastcgi: sudo /sbin/start php-fastcgi
  • Check fastcgi status: sudo /sbin/status php-fastcgi
  • Restart fastcgi: pgrep php-cgi;echo;sudo pkill php-cgi;sleep 1; sudo /sbin/start php-fastcgi; pgrep php-cgi
  • Restart nginx: sudo /etc/init.d/nginx restart

Note: If you see the error “No input file specified”, this may be a permissions issue. Make sure fastcgi and nginx run as the same user (above: www-data). Make sure file permissions are OK.

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 exempl.net

As root :

create a new nginx site file :

nano /etc/nginx/sites-available/exempl.net

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/exempl.net;
      server_name exempl.net;
      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/exempl.net /etc/nginx/sites-enabled/
 
service nginx restart
install/nginx.txt · Last modified: 2017-05-15 19:16 by 212.67.65.190