• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Resolved ServerAlias directive not working correctly after apache update?

johnrdorazio

Basic Pleskian
I'm wondering if the recent security updates to Apache have affected how it handles the ServerAlias directive?

I have an instance of WordPress on one domain, which is working just fine, let's say it's ht.tps://mywordpress.com with Document Root /var/www/vhosts/mywordpress/httpdocs. (I will use a dot in each ht.tps in this thread to prevent automatic linking.)

And I have an instance of MediaWiki on a subdomain, which has started going wonky, let's say it's ht.tps://mediawiki.mywordpress.com with Document Root /var/www/vhosts/mywordpress/mediawiki. This subdomain actually contains an index file that directs towards a number of language wikis which are on the fourth level domain:
  • ht.tps://en.mediawiki.mywordpress.com
  • ht.tps://it.mediawiki.mywordpress.com
  • ht.tps://fr.mediawiki.mywordpress.com
  • etc.
The MediaWiki software is installed in a "w" subdirectory as is the MediaWiki way: /var/www/vhosts/mywordpress/mediawiki/w.

In the VirtualHost config for the MediaWiki instance, in the Additional Apache directives, I have:

Apache config:
ServerAlias *.mediawiki.mywordpress.com

so that any requests to the fourth level will be physically mapped to the same directory as the third level. So if ht.tps://mediawiki.mywordpress.com is mapped to /var/www/vhosts/mywordpress/mediawiki, then ht.tps://en.mediawiki.mywordpress.com will also map to /var/www/vhosts/mywordpress/mediawiki.

For about 6 months now, everything has been working perfectly. After the recent incident with Apache not supporting unix sockets correctly however, my MediaWiki instance has been going haywire. I have since sorted out the issue with Apache, seeing that patches have been released to fix the unix socket issue. So my Apache is back up and running again (I use Nginx 1.20.1 + Apache 2.4.49 + php7.4-fpm), however MediaWiki is still not loading CSS or JS and logins are not working. It's like the load.php script isn't responding, in fact when opening any page in the wiki I can see the text contents, without any styling, and in the browser console a bunch of errors such as:

GET ht.tps://en.mediawiki.mywordpress.com/w/load.php?debug=true&lang=en&modules=ext.visualEditor.desktopArticleTarget.noscript&only=styles&skin=vector net::ERR_ABORTED 404
Main_Page:136 GET ht.tps://en.mediawiki.mywordpress.com/w/load.php?debug=true&lang=en&modules=ext.uls.pt&only=styles&skin=vector net::ERR_ABORTED 404
Main_Page:139 GET ht.tps://en.mediawiki.mywordpress.com/w/load.php?debug=true&lang=en&modules=jquery.makeCollapsible.styles&only=styles&skin=vector net::ERR_ABORTED 404
Main_Page:141 GET ht.tps://en.mediawiki.mywordpress.com/w/load.php?debug=true&lang=en&modules=skins.vector.styles.legacy&only=styles&skin=vector net::ERR_ABORTED 404
Main_Page:142 GET ht.tps://en.mediawiki.mywordpress.com/w/load.php?debug=true&lang=en&modules=wikibase.client.init&only=styles&skin=vector net::ERR_ABORTED 404
Main_Page:138 GET ht.tps://en.mediawiki.mywordpress.com/w/load.php?debug=true&lang=en&modules=ext.wikimediaBadges&only=styles&skin=vector net::ERR_ABORTED 404
Main_Page:145 GET ht.tps://en.mediawiki.mywordpress.com/w/load.php?debug=true&lang=en&modules=site.styles&only=styles&skin=vector net::ERR_ABORTED 404
Main_Page:140 GET ht.tps://en.mediawiki.mywordpress.com/w/load.php?debug=true&lang=en&modules=mediawiki.toc.styles&only=styles&skin=vector net::ERR_ABORTED 404
Main_Page:143 GET ht.tps://en.mediawiki.mywordpress.com/w/load.php?debug=true&lang=en&modules=startup&only=scripts&raw=1&skin=vector net::ERR_ABORTED 404


In order to test why the load.php script is not responding, I decided to test putting a phpinfo.php script in various places.
  • If I place a phpinfo.php at /var/vhosts/mywordpress/mediawiki/phpinfo.php and I try to access ht.tps://mediawiki.mywordpress.com/phpinfo.php, I correctly see the php info page and Document Root is correctly showing as /var/www/vhosts/mywordpress/mediawiki/
  • If I try to access the fourth level ht.tps://en.mediawiki.mywordpress.com/phpinfo.php, I see the phpinfo page but the Document Root is showing as /var/www/vhosts/mywordpress/httpdocs, and not /var/www/vhosts/mywordpress/mediawiki/. So this tells me that ServerAlias directive is NOT working correctly, phpinfo.php is being picked up from the Document Root of the base domain with the WordPress instance.

  • If I place a phpinfo.php at /var/vhosts/mywordpress/mediawiki/w/phpinfo.php and I try to access ht.tps://mediawiki.mywordpress.com/w/phpinfo.php, I again correctly see the php info page with the correct Document Root /var/www/vhosts/mywordpress/mediawiki/.
  • However, if I then try to access the fourth level ht.tps://en.mediawiki.mywordpress.io/w/phpinfo.php, I get redirected to the base domain ht.tps://mywordpress.com with a 404 Page not found error. So this again confirms that the ServerAlias directive is NOT working correctly.

Here are the Rewrite Rules (typical for a MediaWiki setup) in the same VirtualHost config for the MediaWiki instance:

Apache config:
RewriteEngine On

RewriteCond %{HTTP_HOST} ^www\.mediawiki\.wordpress\.com [NC]
RewriteRule ^(.*)$ https://mediawiki.wordpress.com$1 [L,R=301]

RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/w/index.php [L]
# Redirect / to Main Page
RewriteCond %{HTTP_HOST} ^(.*)\.mediawiki\.wordpress\.com$
RewriteRule ^/*$ %{DOCUMENT_ROOT}/w/index.php [L]

I don't believe there are any problems with the Rewrite Rules, because the pages are in fact loading, as text content anyways. Just the PHP scripts (and consequently the CSS and JS loaded by the load.php script) are not working correctly. And this just started happening suddenly, after 6 months without any trouble... And it seems to be concurrent to the problem with Apache, which makes me wonder if it's related.
 
I was able to finally fix this issue by adding a server_name directive for each of the language wikis to the Additional nginx directives in the MediaWiki instance's virtual host panel in Plesk. This gave priority to the MediaWiki instance subdomain over the WordPress domain for the language wiki fourth level domains.
 
Back
Top