From a796434f7714445c61f1a19b572277e363cdc74f Mon Sep 17 00:00:00 2001 From: Kristian Klausen Date: Sat, 20 Mar 2021 15:41:19 +0100 Subject: [PATCH 1/4] archwiki: Implement short URLs The wiki people has been wanting this for some time[1], so let's implement it. This change the url from: https://wiki.archlinux.org/index.php/Main_page to: https://wiki.archlinux.org/title/Main_page [1] https://wiki.archlinux.org/index.php?title=ArchWiki_talk:Requests&oldid=648459#index.php_in_url_address --- roles/archwiki/templates/LocalSettings.php.j2 | 9 +++++++++ roles/archwiki/templates/nginx.d.conf.j2 | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/roles/archwiki/templates/LocalSettings.php.j2 b/roles/archwiki/templates/LocalSettings.php.j2 index 4cd3e4b3..480b4f3d 100644 --- a/roles/archwiki/templates/LocalSettings.php.j2 +++ b/roles/archwiki/templates/LocalSettings.php.j2 @@ -61,3 +61,12 @@ $wgMemCachedServers = [ "unix://{{ archwiki_memcached_socket }}:0" ]; # security headers $wgReferrerPolicy = ["no-referrer-when-downgrade"]; $wgEditPageFrameOptions = "DENY"; + +## The URL base path to the directory containing the wiki; +## defaults for all runtime URL paths are based off of this. +## For more information on customizing the URLs +## (like /w/index.php/Page_title to /wiki/Page_title) please see: +## https://www.mediawiki.org/wiki/Manual:Short_URL +$wgScriptPath = ""; +$wgArticlePath = "/title/$1"; +$wgUsePathInfo = true; diff --git a/roles/archwiki/templates/nginx.d.conf.j2 b/roles/archwiki/templates/nginx.d.conf.j2 index 53036c1e..3176f3c0 100644 --- a/roles/archwiki/templates/nginx.d.conf.j2 +++ b/roles/archwiki/templates/nginx.d.conf.j2 @@ -52,6 +52,11 @@ server { deny all; } + # Redirect old URLs to the new short-url (/title/) + location ~ ^/index.php/(.*)$ { + return 307 /title/$1; + } + # special case due to our '/index.php/Main_Page' type URLs location ~ ^/(?:index|redirect)\.php(?:/.*)$ { access_log /var/log/nginx/{{ archwiki_domain }}/access.log main; @@ -86,6 +91,11 @@ server { add_header X-Cache $upstream_cache_status; } + # Handling for the article path (pretty URLs) + location ^~ /title/ { + rewrite ^ /index.php; + } + # normal PHP FastCGI handler location ~ ^/[^/]+\.php$ { access_log /var/log/nginx/{{ archwiki_domain }}/access.log main; -- GitLab From d75f534dcebcc5c3a8050c7518979f6ca0e749e8 Mon Sep 17 00:00:00 2001 From: Kristian Klausen Date: Wed, 31 Mar 2021 22:56:15 +0200 Subject: [PATCH 2/4] archwiki: Simplify php blocks --- roles/archwiki/templates/LocalSettings.php.j2 | 3 +- roles/archwiki/templates/nginx.d.conf.j2 | 30 ++----------------- 2 files changed, 5 insertions(+), 28 deletions(-) diff --git a/roles/archwiki/templates/LocalSettings.php.j2 b/roles/archwiki/templates/LocalSettings.php.j2 index 480b4f3d..2076aa75 100644 --- a/roles/archwiki/templates/LocalSettings.php.j2 +++ b/roles/archwiki/templates/LocalSettings.php.j2 @@ -69,4 +69,5 @@ $wgEditPageFrameOptions = "DENY"; ## https://www.mediawiki.org/wiki/Manual:Short_URL $wgScriptPath = ""; $wgArticlePath = "/title/$1"; -$wgUsePathInfo = true; +# $wgUsePathInfo is not necessary: https://github.com/wikimedia/mediawiki/blob/bb92c4d1acc029eed0f6848360dff5b2436695fc/includes/WebRequest.php#L151-L153 +#$wgUsePathInfo = true; diff --git a/roles/archwiki/templates/nginx.d.conf.j2 b/roles/archwiki/templates/nginx.d.conf.j2 index 3176f3c0..6f5f6fde 100644 --- a/roles/archwiki/templates/nginx.d.conf.j2 +++ b/roles/archwiki/templates/nginx.d.conf.j2 @@ -57,33 +57,13 @@ server { return 307 /title/$1; } - # special case due to our '/index.php/Main_Page' type URLs - location ~ ^/(?:index|redirect)\.php(?:/.*)$ { - access_log /var/log/nginx/{{ archwiki_domain }}/access.log main; - access_log /var/log/nginx/{{ archwiki_domain }}/access.log.json json_main; - fastcgi_pass archwiki; - fastcgi_index index.php; - fastcgi_split_path_info ^(.+\.php)(.*)$; - if (!-f $document_root$fastcgi_script_name) { - return 404; - } - fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; - fastcgi_param PATH_INFO $fastcgi_path_info; - fastcgi_param HTTPS on; - include fastcgi_params; - } - # special case for '/load.php' type URLs to cache css/js in nginx to relieve php-fpm location = /load.php { access_log /var/log/nginx/{{ archwiki_domain }}/access.log main; access_log /var/log/nginx/{{ archwiki_domain }}/access.log.json json_main; fastcgi_pass archwiki; fastcgi_index index.php; - fastcgi_split_path_info ^(.+\.php)(.*)$; - fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; - fastcgi_param PATH_INFO $fastcgi_path_info; - fastcgi_param HTTPS on; - include fastcgi_params; + include fastcgi.conf; fastcgi_cache wiki; fastcgi_cache_valid 200 10m; @@ -98,16 +78,12 @@ server { # normal PHP FastCGI handler location ~ ^/[^/]+\.php$ { + try_files $uri =404; access_log /var/log/nginx/{{ archwiki_domain }}/access.log main; access_log /var/log/nginx/{{ archwiki_domain }}/access.log.json json_main; fastcgi_pass archwiki; fastcgi_index index.php; - if (!-f $document_root$fastcgi_script_name) { - return 404; - } - fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; - fastcgi_param HTTPS on; - include fastcgi_params; + include fastcgi.conf; } # whitelist known OK directories -- GitLab From 3ca0a6db8504b8c110adb1b73de9110813ae35e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Sat, 24 Apr 2021 20:58:53 +0200 Subject: [PATCH 3/4] archwiki: move the nginx location for /title/ links above /load.php --- roles/archwiki/templates/nginx.d.conf.j2 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/roles/archwiki/templates/nginx.d.conf.j2 b/roles/archwiki/templates/nginx.d.conf.j2 index 6f5f6fde..717eba47 100644 --- a/roles/archwiki/templates/nginx.d.conf.j2 +++ b/roles/archwiki/templates/nginx.d.conf.j2 @@ -57,6 +57,11 @@ server { return 307 /title/$1; } + # Handling for the article path (pretty URLs) + location ^~ /title/ { + rewrite ^ /index.php; + } + # special case for '/load.php' type URLs to cache css/js in nginx to relieve php-fpm location = /load.php { access_log /var/log/nginx/{{ archwiki_domain }}/access.log main; @@ -71,11 +76,6 @@ server { add_header X-Cache $upstream_cache_status; } - # Handling for the article path (pretty URLs) - location ^~ /title/ { - rewrite ^ /index.php; - } - # normal PHP FastCGI handler location ~ ^/[^/]+\.php$ { try_files $uri =404; -- GitLab From b8407cdcc8e54ef5a56b77fa9a977caef67be1ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= Date: Sat, 24 Apr 2021 21:09:50 +0200 Subject: [PATCH 4/4] archwiki: add nginx location block for the new REST API --- roles/archwiki/templates/nginx.d.conf.j2 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/roles/archwiki/templates/nginx.d.conf.j2 b/roles/archwiki/templates/nginx.d.conf.j2 index 717eba47..26c4992d 100644 --- a/roles/archwiki/templates/nginx.d.conf.j2 +++ b/roles/archwiki/templates/nginx.d.conf.j2 @@ -62,6 +62,11 @@ server { rewrite ^ /index.php; } + # Handling for MediaWiki REST API, see https://www.mediawiki.org/wiki/API:REST_API + location ^~ /rest.php/ { + rewrite ^ /rest.php; + } + # special case for '/load.php' type URLs to cache css/js in nginx to relieve php-fpm location = /load.php { access_log /var/log/nginx/{{ archwiki_domain }}/access.log main; -- GitLab