{"id":257,"date":"2013-10-24T21:07:08","date_gmt":"2013-10-24T19:07:08","guid":{"rendered":"http:\/\/www.dereckson.be\/blog\/?p=257"},"modified":"2013-10-27T11:45:32","modified_gmt":"2013-10-27T10:45:32","slug":"mediawiki-nginx-configuration-file","status":"publish","type":"post","link":"https:\/\/www.dereckson.be\/blog\/2013\/10\/24\/mediawiki-nginx-configuration-file\/","title":{"rendered":"MediaWiki nginx configuration file"},"content":{"rendered":"<p><strong>Scenario<\/strong><\/p>\n<ul>\n<li>You have a nginx webserver<\/li>\n<li>You have several MediaWiki installation on this server<\/li>\n<li>You would like to have a simple and clear configuration<\/li>\n<\/ul>\n<p><strong>Solution<\/strong><\/p>\n<p>You want a configuration file you can include in every server {} block MediaWiki is available<\/p>\n<p><strong>Implementation<\/strong><\/p>\n<ol>\n<li>Create a includes subdirectory in your nginx configuration directory (by default, \/usr\/local\/etc\/nginx or \/etc\/nginx).<br \/>\nThis directory can welcome every configuration block you don&#8217;t want to repeat in each server block.<\/li>\n<li>You put in this directory mediawiki-root.conf, mediawiki-wiki.conf or your own configuration block.<\/li>\n<li>In each server block, you can now add the following line:\n<pre>Include includes\/mediawiki-root.conf;<\/pre>\n<\/li>\n<\/ol>\n<p><strong>Configuration I &#8211; MediaWiki in the root web directory, \/article path<br \/>\n<\/strong><\/p>\n<p>This is mediawiki-root.conf on my server:<\/p>\n<pre>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 # Common settings for a wiki powered by MediaWiki with the following configuration:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 #\u00a0\u00a0 (1) MediaWiki is installed in $root folder\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 #\u00a0\u00a0 (2) Article path is \/&lt;title&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 #\u00a0\u00a0 (3) LocalSettings.php contains $wgArticlePath = \"\/$1\"; $wgUsePathInfo = true;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 location \/ {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 try_files $uri $uri\/ \/index.php?$query_string;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 location ~ ^\/images\/thumb\/(archive\/)?[0-9a-f]\/[0-9a-f][0-9a-f]\/([^\/]+)\/([0-9]+)px-.*$ {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 #Note: this doesn't work with InstantCommons.\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if (!-f $request_filename) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 rewrite ^\/images\/thumb\/[0-9a-f]\/[0-9a-f][0-9a-f]\/([^\/]+)\/([0-9]+)px-.*$ \/thumb.php?f=$1&amp;width=$2;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 rewrite ^\/images\/thumb\/archive\/[0-9a-f]\/[0-9a-f][0-9a-f]\/([^\/]+)\/([0-9]+)px-.*$ \/thumb.php?f=$1&amp;width=$2&amp;archived=1;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 location \/images\/deleted\u00a0\u00a0\u00a0 { deny all; }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 location \/cache\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 { deny all; }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 location \/languages\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 { deny all; }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 location \/maintenance\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 { deny all; }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 location \/serialized\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 { deny all; }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 location ~ \/.(svn|git)(\/|$) { deny all; }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 location ~ \/.ht\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 { deny all; }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 location \/mw-config\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 { deny all; }<\/pre>\n<p><strong>Configuration II &#8211; MediaWiki in the \/w directory, \/wiki\/article path<br \/>\n<\/strong><\/p>\n<p>This is mediawiki-wiki.conf on my server:<\/p>\n<pre>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 # Common settings for a wiki powered by MediaWiki with the following configuration:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 #\u00a0\u00a0 (1) MediaWiki is installed in $root\/w folder\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 #\u00a0\u00a0 (2) Article path is \/wiki\/&lt;title&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 #\u00a0\u00a0 (3) LocalSettings.php contains $wgArticlePath = \"\/wiki\/$1\"; $wgUsePathInfo = true;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 location \/wiki {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 try_files $uri $uri\/ \/w\/index.php?$query_string;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 location ~ ^\/w\/images\/thumb\/(archive\/)?[0-9a-f]\/[0-9a-f][0-9a-f]\/([^\/]+)\/([0-9]+)px-.*$ {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 #Note: this doesn't work with InstantCommons.\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if (!-f $request_filename) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 rewrite ^\/w\/images\/thumb\/[0-9a-f]\/[0-9a-f][0-9a-f]\/([^\/]+)\/([0-9]+)px-.*$ \/w\/thumb.php?f=$1&amp;width=$2;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 rewrite ^\/w\/images\/thumb\/archive\/[0-9a-f]\/[0-9a-f][0-9a-f]\/([^\/]+)\/([0-9]+)px-.*$ \/w\/thumb.php?f=$1&amp;width=$2&amp;archived=1;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 location \/w\/images\/deleted\u00a0 { deny all; }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 location \/w\/cache\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 { deny all; }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 location \/w\/languages\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 { deny all; }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 location \/w\/maintenance\u00a0\u00a0\u00a0\u00a0 { deny all; }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 location \/w\/serialized\u00a0\u00a0\u00a0\u00a0\u00a0 { deny all; }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 location ~ \/.(svn|git)(\/|$) { deny all; }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 location ~ \/.ht\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 { deny all; }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 location \/w\/mw-config\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 { deny all; }<\/pre>\n<p><strong>Example of use<\/strong><\/p>\n<p>www.wolfplex.org serves other application is subdirectories and MediaWiki for \/wiki URLs.<\/p>\n<p>This server block:<\/p>\n<ol>\n<li>is a regular one<\/li>\n<li>includes our includes\/mediawiki-wiki.conf configuration file (scenario II)<\/li>\n<li>contains a regular php-fpm block<\/li>\n<li>contains other instructions<\/li>\n<\/ol>\n<pre>\u00a0\u00a0\u00a0 server {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 listen\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 80;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 server_name\u00a0\u00a0\u00a0\u00a0 www.wolfplex.org\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 access_log\u00a0\u00a0\u00a0\u00a0\u00a0 \/var\/log\/www\/wolfplex.org\/www-access.log main;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 error_log\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/var\/log\/www\/wolfplex.org\/www-error.log;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 root\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/var\/wwwroot\/wolfplex.org\/www;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 index\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 index.html index.php index.htm;\r\n\r\n        [...]\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 include\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 includes\/mediawiki-wiki.conf;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 location \/ {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 #Link to the most relevant page to present the project\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 rewrite \/presentation\/?$ \/w\/index.php?title=Presentation last;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 #Link to the most relevant page for bulletin\/news information:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 rewrite \/b\/?$ \/w\/index.php?title=Bulletin:Main last;\r\n\r\n            [...]\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\r\n        [...]\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 location ~ \\.php$ {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 try_files $uri =404;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 fastcgi_pass\u00a0\u00a0 127.0.0.1:9010;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 fastcgi_param\u00a0 SCRIPT_FILENAME\u00a0 $document_root$fastcgi_script_name;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 include\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 fastcgi_params;\r\n\u00a0\u00a0\u00a0     }\r\n    }<\/pre>\n<p><strong>Some notes<\/strong><\/p>\n<ul>\n<li>Configuration is based on Daniel Friesen&#8217;s <a itemprop=\"url\" title=\"MediaWiki Short URL Builder\" href=\"http:\/\/blog.redwerks.org\/2012\/02\/23\/mediawiki-short-url-builder\/\" rel=\"bookmark\">MediaWiki Short URL Builder<\/a>, who collected various working nginx ones. There are some differences in the rewrite, our goal here is to have a generic configuration totally agnostic of the way .php files are handled.<\/li>\n<li>Our configuration (not the one generated by the builder) uses a if for the thumbnails handler. The nginx culture is a culture where you should try something else than an if. See <a title=\"IfIsEvil\" href=\"http:\/\/wiki.nginx.org\/IfIsEvil\">this nginx wiki page<\/a> and <a title=\"How nginx &quot;location if&quot; works\" href=\"http:\/\/agentzh.blogspot.be\/2011\/03\/how-nginx-location-if-works.html\">this post about the location if way of work<\/a> for more information.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Scenario You have a nginx webserver You have several MediaWiki installation on this server You would like to have a simple and clear configuration Solution You want a configuration file you can include in every server {} block MediaWiki is available Implementation Create a includes subdirectory in your nginx configuration directory (by default, \/usr\/local\/etc\/nginx or [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[50,30],"tags":[100,101],"class_list":["post-257","post","type-post","status-publish","format-standard","hentry","category-sysadmin","category-wikimedia","tag-mediawiki","tag-nginx"],"_links":{"self":[{"href":"https:\/\/www.dereckson.be\/blog\/wp-json\/wp\/v2\/posts\/257","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dereckson.be\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dereckson.be\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dereckson.be\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dereckson.be\/blog\/wp-json\/wp\/v2\/comments?post=257"}],"version-history":[{"count":4,"href":"https:\/\/www.dereckson.be\/blog\/wp-json\/wp\/v2\/posts\/257\/revisions"}],"predecessor-version":[{"id":261,"href":"https:\/\/www.dereckson.be\/blog\/wp-json\/wp\/v2\/posts\/257\/revisions\/261"}],"wp:attachment":[{"href":"https:\/\/www.dereckson.be\/blog\/wp-json\/wp\/v2\/media?parent=257"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dereckson.be\/blog\/wp-json\/wp\/v2\/categories?post=257"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dereckson.be\/blog\/wp-json\/wp\/v2\/tags?post=257"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}