Welcome! Log In Create A New Profile

Advanced

Nginx config for multiple Mediawikis

Posted by teer 
Nginx config for multiple Mediawikis
July 28, 2024 04:11PM
Hello Nginx team,

I have a problem with using multiple Mediawikis on my Nginx webserver.

I want each language to have its own wiki:
https://example.org/wiki/en/
https://example.org/wiki/fr/
etc...

I installed these two (see: https://www.mediawiki.org/wiki/Manual:Wiki_family).


Problem:
Nginx does not distinguish between my different wikis.
It either reverts to the English wiki, or goes to example.org/wiki/ (with no language subdirectory e.g. /en/, /fr/) which is wrong.

Example:
Trying to make an article on `example.org/wiki/fr/` called `Test2` creates it on the English wiki instead.
And as you can see below, it opens up `Edit` on the bare `/wiki/` URL:

`/var/log/nginx/example.org/access.log`
11.22.33.44 - - [28/Jul/2024:19:38:24 +0000] "POST /wiki/api.php HTTP/1.1" 499 0 "https://example.org/wiki/index.php?title=Test2&action=edit" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Firefox/128.0"
11.22.33.44 - - [28/Jul/2024:19:38:25 +0000] "POST /wiki/index.php?title=Test2&action=submit HTTP/1.1" 302 5 "https://example.org/wiki/index.php?title=Test2&action=edit" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Firefox/128.0"
11.22.33.44 - - [28/Jul/2024:19:38:25 +0000] "GET /wiki/en/Test2 HTTP/1.1" 200 4827 "https://example.org/wiki/index.php?title=Test2&action=edit" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Firefox/128.0"
11.22.33.44 - - [28/Jul/2024:19:38:26 +0000] "GET /wiki/load.php?lang=en&modules=jquery%2Coojs-ui-core%7Cmediawiki.action.view.postEdit%7Cmediawiki.notification%2CtempUserCreated%2CvisibleTimeout%7Coojs-ui-core.icons%2Cstyles%7Coojs-ui.styles.indicators&skin=vector&version=pk8ox HTTP/1.1" 200 429889 "https://example.org/wiki/en/Test2" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Firefox/128.0"


Directory layout:
/srv/live/php/mediawiki-1.42.1/
-----settings/
----------example.org/
---------------LocalSettings.en.php
---------------LocalSettings.fr.php
LocalSettings.php


# example.org (see attached for full file)
server
{
ssl_certificate /etc/letsencrypt/live/example.org/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.org/privkey.pem; # managed by Certbot

listen 443 ssl;
server_name example.org;
root /srv/live/static/example.org/www;

access_log /var/log/nginx/example.org/access.log;
error_log /var/log/nginx/example.org/error.log;


location ^~ /wiki/
{
alias /srv/live/php/mediawiki-1.42.1/;

# Redirect /wiki/ to /wiki/en/
location = /wiki/
{
return 301 $scheme://$host/wiki/en/;
}

try_files $uri $uri/ @mediawiki;

# PHP handling for wiki
location ~ \.php$
{
fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param MW_DB $arg_lang;
include fastcgi_params;
}
}

location @mediawiki
{
set $lang 'en';
if ($uri ~ "^/wiki/(en|fr)/")
{
set $lang $1;
}

set $wiki_id 'example_org_en';
if ($lang = 'fr')
{
set $wiki_id 'example_org_fr';
}

rewrite "^/wiki/([a-z]{2})/(.*)$" /wiki/index.php?title=$2&lang=$1 last;
fastcgi_param MW_DB $wiki_id;
}
}


Anyone who can help me with this will have my undying gratitude. I have been struggling with this for almost a month.
Thanks in advance,
teer
Attachments:
open | download - example.org.conf (2.2 KB)
open | download - LocalSettings.php (6.8 KB)
open | download - LocalSettings.fr.php (138 bytes)
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 186
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready