Руководство:Short URL/ru

From mediawiki.org
This page is a translated version of the page Manual:Short URL/Nginx and the translation is 92% complete.

В этом руководстве предполагается, что файлы вики будут расположены в каталоге /w/. Статьи будут выводиться по URL, начинающемуся с /wiki/.

nginx.conf

Добавьте выделенные настройки в область видимости сервера и перезагрузите nginx.

Если область видимости вашего сервера не находится в nginx.conf, найдите ее из поддиректорий conf.d/ или sites-available/.

Если вы хотите использовать другой путь к корню сайта или статье, вы можете использовать для автоматической генерации конфигурации сайт генерации коротких URL-адресов от Redwerks.

server {
	# [...]

	# Расположение точек входа в вики
	location ~ ^/w/(index|load|api|thumb|opensearch_desc|rest|img_auth)\.php$ {
		include /etc/nginx/fastcgi_params;
		fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
		fastcgi_pass 127.0.0.1:9000; # or whatever port your PHP-FPM listens on
	}
	
	# Изображения
	location /w/images {
		# Separate location for images/ so .php execution won't apply
	}
	location /w/images/deleted {
		# Deny access to deleted images folder
		deny all;
	}
	# Ресурсы MediaWiki (обычно изображения)
	location ~ ^/w/resources/(assets|lib|src) {
		try_files $uri =404;
		add_header Cache-Control "public";
		expires 7d;
	}
	# Ресурсы, скрипты и стили из тем оформления и расширений
	location ~ ^/w/(skins|extensions)/.+\.(css|js|gif|jpg|jpeg|png|svg|wasm|ttf|woff|woff2)$ {
		try_files $uri =404;
		add_header Cache-Control "public";
		expires 7d;
	}
	# Фавикон
	location = /favicon.ico {
		alias /w/images/6/64/Favicon.ico;
		add_header Cache-Control "public";
		expires 7d;
	}

	# License and credits files
	location ~ ^/w/(COPYING|CREDITS)$ {
		default_type text/plain;
	}
	
	## Uncomment the following code if you wish to use the installer/updater
	## installer/updater
	#location /w/mw-config/ {
	#	# Do this inside of a location so it can be negated
	#	location ~ \.php$ {
	#		include /etc/nginx/fastcgi_params;
	#		fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
	#		fastcgi_pass 127.0.0.1:9000; # or whatever port your PHP-FPM listens on
	#	}
	#}
	
	# Handling for Mediawiki REST API, see [[mw:API:REST_API]]
	location /w/rest.php/ {
		try_files $uri $uri/ /w/rest.php?$query_string;
	}

	## Uncomment the following code for handling image authentication
	## Also add "deny all;" in the location for /w/images above
	#location /w/img_auth.php/ {
	#	try_files $uri $uri/ /w/img_auth.php?$query_string;
	#}

	# Handling for the article path (pretty URLs)
	location /wiki/ {
		rewrite ^/wiki/(?<pagename>.*)$ /w/index.php;
	}

	# Allow robots.txt in case you have one
	location = /robots.txt {
	}
	# Explicit access to the root website, redirect to main page (adapt as needed)
	location = / {
		return 301 /wiki/Main_Page;
	}

	# Every other entry point will be disallowed.
	# Add specific rules for other entry points/images as needed above this
	location / {
		return 404;
	}
}

LocalSettings.php

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

См. также