ansible/roles/mediawiki/templates/nginx.j2

59 lines
1.5 KiB
Django/Jinja

# {{ ansible_managed }}
server {
{{ mediawiki_nginx_conf }}
location ~ ^{{ mediawiki_path }}/(index|load|api|thumb|opensearch_desc|rest|img_auth)\.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass {{ mediawiki_php_socket }};
}
# Images
location {{ mediawiki_path }}/images {
# Separate location for images/ so .php execution won't apply
}
location {{ mediawiki_path }}/images/deleted {
# Deny access to deleted images folder
deny all;
}
# MediaWiki assets (usually images)
location ~ ^{{ mediawiki_path }}/resources/(assets|lib|src) {
try_files $uri 404;
add_header Cache-Control "public";
expires 7d;
}
# Assets, scripts and styles from skins and extensions
location ~ ^{{ mediawiki_path }}/(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 {
add_header Cache-Control "public";
expires 7d;
}
location {{ mediawiki_path }}/rest.php/ {
try_files $uri $uri/ {{ mediawiki_path }}/rest.php?$query_string;
}
# Handling for the article path (pretty URLs)
location /wiki/ {
rewrite ^/wiki/(?<pagename>.*)$ {{ mediawiki_path }}/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/Hauptseite;
}
location / {
return 404;
}
}