Skip to content

Instantly share code, notes, and snippets.

@Dianliang233
Last active July 27, 2022 11:39
Show Gist options
  • Save Dianliang233/71b8f598cb9da8fae4442ab2d2748045 to your computer and use it in GitHub Desktop.
Save Dianliang233/71b8f598cb9da8fae4442ab2d2748045 to your computer and use it in GitHub Desktop.
小可 · Wiki nginx pseudo-static config
# Location for wiki's entry points
location ~ ^/(index|load|api|thumb|opensearch_desc|rest|img_auth)\.php$ {
include enable-php-81.conf;
}
# Cache for load.php
location ~ ^load\.php$ {
add_header Cache-Control "public";
expires 7d;
}
# Images
location /images {
# Separate location for images/ so .php execution won't apply
add_header Cache-Control "public";
expires 7d;
}
location /images/deleted {
# Deny access to deleted images folder
deny all;
}
# MediaWiki assets (usually images)
location ~ ^/resources/(assets|lib|src) {
try_files $uri 404;
add_header Cache-Control "public";
expires 7d;
}
# Assets, scripts and styles from skins and extensions
location ~ ^/(skins|extensions)/.+\.(woff2|css|js|gif|jpg|jpeg|png|svg|wasm)$ {
try_files $uri 404;
add_header Cache-Control "public";
expires 7d;
}
# Favicon
location = /favicon.ico {
add_header Cache-Control "public";
expires 7d;
}
# License and credits files
location ~ ^/(COPYING|CREDITS) {
default_type text/plain;
}
## Uncomment the following code if you wish to use the installer/updater
## installer/updater
location /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
# }
deny all;
}
# Handling for Mediawiki REST API, see [[mw:API:REST_API]]
location /rest.php/ {
try_files $uri $uri/ /rest.php?$query_string;
}
## Uncomment the following code for handling image authentication
## Also add "deny all;" in the location for /images above
#location /img_auth.php/ {
# try_files $uri $uri/ /img_auth.php?$query_string;
#}
# Handling for the article path (pretty URLs)
location /wiki/ {
rewrite ^/wiki/(?<pagename>.*)$ /index.php;
}
# Allow robots.txt in case you have one
location = /robots.txt {
}
# Root will not be redirected to /wiki/
location = / {
}
# This redirects to curid, useful for shorter URL
location /-/ {
rewrite ^/-/(\d+) /wiki/?curid=$1 last;
}
# Every other entry point will be redirected to /wiki/
location / {
rewrite ^/(.*) /wiki/$1 redirect;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment