Manual:Short URL/Page title - nginx, Root Access, PHP as a CGI module
|
Warning: This Short URL page contains bad advice on how to configure your server that could lead to some pages on your wiki not working and/or may cause you issues while upgrading. This guide remains simply because an official guide on how to configure short URLs on this wiki has not been created yet. |
This example configuration:
- Known to work with MediaWiki 1.13.x through 1.21.x. It has not been tested with earlier versions.
- This short URL format has been extensively tested for two years in a public environment and has shown no issues. It has also been adapted to be used Gamepedia's wiki farm.
- Was designed for an Ubuntu Linux distribution. It should work under other Linux distributions with minor tweaking. It should work in Windows as well with more tweaking to the folder paths.
- The wiki is installed in the root html/http directory. Example: /home/user/public_html OR /var/www for other Linux distributions.
- Pages will be accessed at example.com/Page_Title or www.example.com/Page_Title. This will also work as wiki.example.com/Page_Title as any subdomain should work under the server_name directive and a minor tweak to LocalSettings.php.
- Page can still be accessed with example.com/index.php/Page_Title and example.com/index.php?title=Page_Title. This is great since if your wiki has been up previously old search engine links and bookmarks will continue to work.
- Viewing File:Image.jpg files and similar with a period in the name will work with this setup.
- Static files will be served with max expiration header to reduce load on the server.
- This configuration will work with robots.txt and other files stuck in the root directory. This script checks for the existence of the file to serve directly before passing the URI request off to MediaWiki.
The following nginx configuration can be added directly into the /etc/nginx/nginx.conf file for a server hosting one site or into a /etc/nginx/sites-available/example.com file setup for a server with multiple sites. Make sure to change the server_name, the root, and access/error log file names.
server {
server_name www.example.com example.com;
listen 80;
root /home/user/public_html;
index index.php index.html index.htm;
access_log /var/log/nginx/access-example.log;
error_log /var/log/nginx/error-example.log;
location ~ \.htaccess {
deny all;
}
location / {
if (!-e $request_filename) {
rewrite ^/([^?]*)(?:\?(.*))? /index.php?title=$1&$2 last;
}
if ($uri ~* "\.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$") {
expires max;
break;
}
}
location ~* \.php$ {
if (!-e $request_filename) {
return 404;
}
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
- Edit the LocalSettings.php file in the root html directory and add/update these settings:
$wgScriptPath = ""; $wgArticlePath = "/$1"; $wgUsePathInfo = true; $wgScriptExtension = ".php";
If you added the configuration into a sites-available configuration folder make sure to create the symlink into the sites-enabled folder. Reload your nginx configuration by typing: /etc/init.d/nginx reload

