I have an instance of WordPress set up at https://wordpressinstance.example
.
I have an instance of MediaWiki set up at https://mediawiki.wordpressinstance.example.
The MediaWiki instance is multilingual, and each language wiki is accessible from the fourth level:
- English :
https://en.mediawiki.wordpressinstance.example
- Italian :
https://it.mediawiki.wordpressinstance.example
- etc.
I have an Apache Virtual Host for the WordPress instance, with document root set to /var/www/vhosts/wordpressinstance/httpdocs.
I have an Apache Virtual Host for the MediaWiki instance, with document root set to /var/www/vhosts/wordpressinstance/mediawiki.
In order for the fourth level domains to point at the same document root as the third level domain in the MediaWiki instance, I have a wildcard ServerAlias directive:
ServerAlias *.mediawiki.wordpressinstance.example
And these are the rewrite rules in the Virtual host configuration for the MediaWiki:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.mediawiki\.wordpressinstance\.example [NC]
RewriteRule ^(.*)$ https://mediawiki.wordpressinstance.example$1 [L,R=301]
RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/w/index.php [L]
# Redirect / to Main Page
RewriteCond %{HTTP_HOST} ^(.*)\.mediawiki\.wordpressinstance\.example$
RewriteRule ^/*$ %{DOCUMENT_ROOT}/w/index.php [L]
This setup has been working nicely for at least 6 months now, however recently the MediaWiki instance started acting strangely, it won't load CSS or JS resources apparently. When accessing https://en.mediawiki.wordpressinstance.example
(which correctly redirecs to https://en.mediawiki.wordpressinstance.example/wiki/Main_Page,
I'm seeing these errors:
GET https://en.mediawiki.wordpressinstance.io/w/load.php?debug=true&lang=en&modules=ext.uls.pt&only=styles&skin=vector net::ERR_ABORTED 404
Main_Page:138 GET `https://en.mediawiki.wordpressinstance.example/w/load.php?debug=true&lang=en&modules=ext.wikimediaBadges&only=styles&skin=vector` net::ERR_ABORTED 404
Main_Page:139 GET `https://en.mediawiki.wordpressinstance.example/w/load.php?debug=true&lang=en&modules=jquery.makeCollapsible.styles&only=styles&skin=vector` net::ERR_ABORTED 404
Main_Page:137 GET `https://en.mediawiki.wordpressinstance.example/w/load.php?debug=true&lang=en&modules=ext.visualEditor.desktopArticleTarget.noscript&only=styles&skin=vector` net::ERR_ABORTED 404
Main_Page:140 GET `https://en.mediawiki.wordpressinstance.example/w/load.php?debug=true&lang=en&modules=mediawiki.toc.styles&only=styles&skin=vector` net::ERR_ABORTED 404
Main_Page:142 GET `https://en.mediawiki.wordpressinstance.example/w/load.php?debug=true&lang=en&modules=wikibase.client.init&only=styles&skin=vector` net::ERR_ABORTED 404
Main_Page:141 GET `https://en.mediawiki.wordpressinstance.example/w/load.php?debug=true&lang=en&modules=skins.vector.styles.legacy&only=styles&skin=vector` net::ERR_ABORTED 404
Main_Page:143 GET `https://en.mediawiki.wordpressinstance.example/w/load.php?debug=true&lang=en&modules=startup&only=scripts&raw=1&skin=vector` net::ERR_ABORTED 404
Main_Page:145 GET `https://en.mediawiki.wordpressinstance.example/w/load.php?debug=true&lang=en&modules=site.styles&only=styles&skin=vector` net::ERR_ABORTED 404
If I try accessing the MediaWiki load script directly (https://en.mediawiki.wordpressinstance.example/w/load.php),
I simply get redirected to the base domain (https://wordpressinstance.example
) with a "404 page not found" error.
I have done some tests to see what is happening here. I created a phpinfo.php file under /var/www/vhosts/wordpressinstance/httpdocs, under /var/www/vhosts/wordpressinstance/mediawiki, and under /var/www/vhosts/wordpressinstance/mediawiki/w.
- Accessing
https://mediawiki.wordpressinstance.example/phpinfo.php
correctly shows PHP info, and correctly shows /var/www/vhosts/wordpressinstance/mediawiki as document root - Accessing
https://en.mediawiki.wordpressinstance.example/phpinfo.php
also shows PHP info, however incorrectly shows /var/www/vhosts/wordpressinstance/httpdocs as document root
This brings me to believe that the Apache ServerAlias directive is not working correctly. But since it has been working correctly for the past 6 months, and only started to go wonky just recently, I wonder if it maybe has something to do with recent changes to Apache?
The only changes on my server that could possibly affect something like this, were:
- an update from Apache 2.4.48 to Apache 2.4.49 a little over a week ago that screwed up my PHP-FPM instances, which are available over unix sockets
- to fix that, I removed Ondrej Sury's Apache PPA, removed Apache, and reinstalled the system Apache (I'm on Ubuntu 20.04, which installed Apache 2.4.41)
- This got the websites back up again, for about a week, then they all went offline again
- In the meantime I had opened issues on the Plesk community forum, on Ondrej Sury's github repo for his Apache PPA, and on the Apache mailing list. Apache acknowledged the error, and has put fixes in place, which Ondrej Sury pulled into his Apache 2.4.49 build
- Following Ondrej Sury's latest updates, I added his PPA back and updated Apache, which is now back to v2.4.49 and is correctly communicating with PHP7.4-FPM over unix sockets
- All websites are back up again, only MediaWiki is acting strangely, not loading CSS or JS and not allowing logins
And going back to the phpinfo.php tests:
- Accessing
https://mediawiki.wordpressinstance.example/w/phpinfo.php
correctly shows PHP info and the document root is correctly set to /var/www/vhosts/wordpressinstance/mediawiki - Accessing
https://en.mediawiki.wordpressinstance.example/w/phpinfo.php
redirects to the base domainhttps://wordpressinstance.example
with a 404 page not found error
ServerName
andServerAlias
directives in each of these vHosts? (Port 80 and Port 443.) In what order are they being loaded? AreServerName
,ServerAlias
orDocumentRoot
defined outside of these vHost containers in the main server config?https://en.mediawiki.wordpressinstance.example/w/phpinfo.php
redirects to the base domainhttps://wordpressinstance.example
" - Redirects to the root? Or to the same URL-path (ie./w/phpinfo.php
) but at the other host? Find the possible "redirect" directives that might be doing this and change the HTTP status (eg. to 307 or 303) and see if this is reflected in the browser's response.