Manual:Short URL/Nginx

Jump to: navigation, search

Other languages:
English • ‎한국어
The content on this page is vastly incomplete! It does not contain important settings. E.g. using the below information, your wiki will reveal private data to the public. Instead, use the short URL service by Redwerks to automatically generate a configuration, which solves these issues. An example of such a configuration should be added here!

This guide expects the wiki files to be installed in folder /wiki. The articles will be output in the webroot.


Rewriting in nginx is very simple. Just add highlighted settings to server scope and reload nginx, then it works.
If your server scope is not in nginx.conf, find it from conf.d/ or sites-available/ subdirs.

 1 # PHP-FPM
 2 location ~ \.php$ {
 3     fastcgi_pass;
 4     ...
 5 }
 7 # In the "main folder" (no-slash) and in the folder wiki (/wiki/ then no-slash) rewrite the *.php5 files
 8 # (which have been deprecated since MediaWiki 1.25) to their *.php equivalents.
 9 rewrite ^/([^/]*)\.php5 /$1.php permanent;
10 rewrite ^(/wiki/[^/]*\.php)5 $1 permanent; 
12 # MediaWiki shortcut rule
13 location /wiki/ {
14     if ($request_uri ~ ^/wiki/images)     { break; }
15     if ($request_uri ~ ^/wiki/resources)  { break; }
16     if ($request_uri ~ ^/wiki/index\.php) { break; }
17     if ($request_uri ~ ^/wiki/api\.php)  { break; }
18     if ($request_uri ~ ^/wiki/load\.php)  { break; }
19     rewrite ^/wiki/(.+)$ /wiki/index.php?title=$1 last;
20 }

Note that this configuration makes use of if constructs, which should be avoided whenever possible.


$wgScriptPath  = "/wiki";
$wgArticlePath = "$wgScriptPath/$1";

See also[edit]