Manual:Short URL/Page title - nginx, Root Access, PHP as a CGI module/zh

From MediaWiki.org
Jump to navigation Jump to search
This page is a translated version of the page Manual:Short URL/Page title - nginx, Root Access, PHP as a CGI module and the translation is 50% complete.

Other languages:
English • ‎中文 • ‎日本語

配置:

  • MediaWiki 1.21至1.27已测试能正常运行。
  • 短URL格式在两年多的公开环境中被广泛测试。 并且被改编用于Gamepedia's 维基农场。
  • 它是为 Ubuntu Linux 发行版设计的。 它在其他 Linux 发行版下工作只需少量调整。 而在 Windows中工作的话, 则需要在文件夹路径上做较多改动。
  • 维基站点被安装于根目录下的html/http目录。例如:为其他Linux发行版的/home/user/public_html/var/www
  • 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.

nginx配置

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.

The content on this page is vastly incomplete! It does not contain important settings. E.g. using the below information, your wiki will reveal private data to the public. Instead, use the short URL service by Redwerks to automatically generate a configuration, which solves these issues. An example of such a configuration should be added here!
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 ~ \.ht {
		deny all;
	}

	location / {
		try_files $uri $uri/ @rewrite;
	}

	location @rewrite {
		rewrite ^/(.*)$ /index.php;
	}

	location ^~ /maintenance/ {
		return 403;
	}

	location ~ \.php$ {
		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;

		try_files $uri @rewrite;
	}
}
  • 编辑站点根目录下的LocalSettings.php文件,然后添加/更新这些设置:
$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

参见