ShortURL配置/nginx

来自istudylinux

环境

名称 内容
网页root目录 /var/www/html
mw文件夹 /var/www/html/myGod
LocalSettings.php /var/www/html/myGod/LocalSettings.php
nginx配置文件 /etc/nginx/site-enabled/mywiki.conf
最后URL结果 http://mw.istudylinux.cn/wiki/首页

仅需要更改两个地方。[1]

mywiki.conf

下面的内容可以更改两个地方,一个是mywiki,一个是66行后的wiki字段。

  • myGod就是上面的mw文件夹名称
  • wiki就是你改动后的URL后面首页前面的名称,也可以改为fun,boy,abc,随你喜好
server {
	root /var/www/html;
	...
	# Location for wiki's entry points
	location ~ ^/myGod/(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
	}
	
	# Images
	location /myGod/images {
		# Separate location for images/ so .php execution won't apply
	}
	location /myGod/images/deleted {
		# Deny access to deleted images folder
		deny all;
	}
	# MediaWiki assets (usually images)
	location ~ ^/myGod/resources/(assets|lib|src) {
		try_files $uri 404;
		add_header Cache-Control "public";
		expires 7d;
	}
	# Assets, scripts and styles from skins and extensions
	location ~ ^/myGod/(skins|extensions)/.+\.(css|js|gif|jpg|jpeg|png|svg|wasm)$ {
		try_files $uri 404;
		add_header Cache-Control "public";
		expires 7d;
	}
	# Favicon
	location = /favicon.ico {
		alias /myGod/images/6/64/Favicon.ico;
		add_header Cache-Control "public";
		expires 7d;
	}

	# License and credits files
	location ~ ^/myGod/(COPYING|CREDITS)$ {
		default_type text/plain;
	}
	
	## Uncomment the following code if you wish to use the installer/updater
	## installer/updater
	#location /myGod/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 /myGod/rest.php/ {
		try_files $uri $uri/ /myGod/rest.php?$query_string;
	}

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

	# Handling for the article path (pretty URLs)
	location /wiki/ {
		rewrite ^/wiki/(?<pagename>.*)$ /myGod/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/首页;
	}
	...
}

LocalSettings.php

在页面后面添加如下内容:

# 配置shortURL
$wgScriptPath = "/myGod";
$wgArticlePath = "/wiki/$1";
$wgUsePathInfo = true;

参考