Jump to content
MediaWiki

Manual:Short URL/Nginx

From mediawiki.org
Please expand this page. More information might be found on the talk page.

This guide expects the wiki files to be installed in folder /w/. The articles will be output under URLs starting with /wiki/.

nginx.conf

[edit ]

Add the highlighted settings to server scope and reload nginx.

If your server scope is not in nginx.conf, find it from conf.d/ or sites-available/ subdirs.

If you would like a different root or article path, you may use the short URL service by Redwerks to automatically generate a configuration.

server{
# [...]

# Location for wiki's entry points
location~^/w/(mw-config/)?(index|load|api|thumb|opensearch_desc|rest|img_auth)\.php${
# Use the following "location", instead, to disable the MediaWiki web installer/updater.
# location ~ ^/w/(index|load|api|thumb|opensearch_desc|rest|img_auth)\.php$ {
include/etc/nginx/fastcgi_params;
fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;
fastcgi_pass127.0.0.1:9000;# or whatever port your PHP-FPM listens on
# fastcgi_pass unix:/run/php-fpm/www.sock; # Default for RHEL & derivatives
# fastcgi_pass unix:/run/php/php8.1-fpm.sock; # Default for Debian & derivatives
# (adjust for PHP version)
}

# Images
location/w/images{
# Separate location for images/ so .php execution won't apply
# as required starting from v1.40
add_headerX-Content-Type-Options"nosniff";
# Serve uploaded HTML as plaintext, don't execute SHTML
types{text/plainhtmlhtmshtmlphtml;}
}
location/w/images/deleted{
# Deny access to deleted images folder
denyall;
}
# MediaWiki assets (usually images)
location~^/w/resources/(assets|lib|src){
try_files$uri=404;
add_headerCache-Control"public";
expires7d;
}
# Assets, scripts and styles from skins and extensions
location~^/w/(skins|extensions)/.+\.(css|js|gif|jpg|jpeg|png|svg|wasm|ttf|woff|woff2)${
try_files$uri=404;
add_headerCache-Control"public";
expires7d;
}
# Favicon
location=/favicon.ico{
alias/w/images/6/64/Favicon.ico;
add_headerCache-Control"public";
expires7d;
}

# License and credits files
location~^/w/(COPYING|CREDITS)${
default_typetext/plain;
}

# 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=/{
return301/wiki/Main_Page;
}

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

LocalSettings.php

[edit ]
$wgScriptPath = "/w";
$wgArticlePath = "/wiki/1ドル";
$wgUsePathInfo = true;

See also

[edit ]

AltStyle によって変換されたページ (->オリジナル) /