Manual:Short URL/Nginx

From MediaWiki.org
Jump to navigation Jump to search
Translate this page; This page contains changes which are not marked for translation.

Other languages:
English • ‎한국어

This guide expects the wiki files to be installed in folder /w/. The articles will be output under urls starting with /wiki/.

nginx.conf[edit]

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.
If you would like a different root or article path, you may use the short URL service by Redwerks to automatically generate a configuration.

 1 server {
 2 	# [...]
 3 
 4 	# Location for the wiki's root
 5 	location /w/ {
 6 		# Do this inside of a location so it can be negated
 7 		location ~ \.php$ {
 8 			try_files $uri $uri/ =404; # Don't let php execute non-existent php files
 9 			include /etc/nginx/fastcgi_params;
10 			fastcgi_pass 127.0.0.1:9000; # or whatever port your PHP-FPM listens on
11 		}
12 	}
13 	
14 	location /w/images {
15 		# Separate location for images/ so .php execution won't apply
16 	}
17 	location /w/images/deleted {
18 		# Deny access to deleted images folder
19 		deny	all;
20 	}
21 	
22 	# Deny access to folders MediaWiki has a .htaccess deny in
23 	location /w/cache       { deny all; }
24 	location /w/languages   { deny all; }
25 	location /w/maintenance { deny all; }
26 	location /w/serialized  { deny all; }
27 	
28 	# Just in case, hide .svn and .git too
29 	location ~ /.(svn|git)(/|$) { deny all; }
30 	
31 	# Hide any .htaccess files
32 	location ~ /.ht { deny all; }
33 	
34 	# Uncomment the following code if you wish to hide the installer/updater
35 	## Deny access to the installer
36 	#location /w/mw-config { deny all; }
37 	
38 	# Handling for the article path
39 	location /wiki {
40 		include /etc/nginx/fastcgi_params;
41 		# article path should always be passed to index.php
42 		fastcgi_param SCRIPT_FILENAME	$document_root/w/index.php;
43 		fastcgi_pass  127.0.0.1:9000; # or whatever port your PHP-FPM listens on
44 	}
45 	
46 	# [...]
47 }

LocalSettings.php[edit]

$wgScriptPath = "/w";
$wgScriptExtension = ".php";
$wgArticlePath = "/wiki/$1";
$wgUsePathInfo = true;

See also[edit]