The ngnix.conf snippet

From Peter
Revision as of 08:33, 22 December 2016 by Perdurabo (talk | contribs) (Normal)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


Use this configuration within your nginx configuration inside the `server {}` where I have already defined your Wikinormal installation in.

Note that this is not a complete configuration. The configuration between the # [...]'s is meant to be inserted into your existing configuration only replacing small bits of it that have been obsoleted.

server { # [...]

# Location for the wiki's root location / { # Do this inside of a location so it can be negated location ~ \.php$ { try_files $uri $uri/ =404; # Don't let php execute non-existent php files include /etc/nginx/fastcgi_params; fastcgi_pass; } }

location /images { # Separate location for images/ so .php execution won't apply

location ~ ^/images/thumb/(archive/)?[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ { # Thumbnail handler for MediaWiki # This location only matches on a thumbnail's url # If the file does not exist we use @thumb to run the thumb.php script try_files $uri $uri/ @thumb; } } location /images/deleted { # Deny access to deleted images folder deny all; }

# Deny access to folders MediaWiki has a .htaccess deny in location /cache { deny all; } location /languages { deny all; } location /maintenance { deny all; } location /serialized { deny all; }

# Just in case, hide .svn and .git too location ~ /.(svn|git)(/|$) { deny all; }

# Hide any .htaccess files location ~ /.ht { deny all; }

# Uncomment the following code if you wish to hide the installer/updater ## Deny access to the installer #location /mw-config { deny all; }

# Handling for the article path location /wiki { include /etc/nginx/fastcgi_params; # article path should always be passed to index.php fastcgi_param SCRIPT_FILENAME $document_root/index.php; fastcgi_pass; }

# Thumbnail 404 handler, only called by try_files when a thumbnail does not exist location @thumb { # Do a rewrite here so that thumb.php gets the correct arguments rewrite ^/images/thumb/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ /thumb.php?f=$1&width=$2; rewrite ^/images/thumb/archive/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ /thumb.php?f=$1&width=$2&archived=1;

# Run the thumb.php script include /etc/nginx/fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root/thumb.php; fastcgi_pass; }

# [...] }
This snippet of code needs to know what fastcgi_pass to use for your php configuration. You can replace the fastcgi_pass [...] with a proper fastcgi_pass or fill in the value below and we'll give you the configuration to use. If you have a fastcgi_params file that's not in the typical location you can also specify it below.