Score:0

Apache httpd on a backup machine where hostname is not matching

jp flag

I have to run an Apache httpd server on a backup machine, which is a CentOS. In this case, it is a WordPress multisite installation. Since it is a backup machine, the DNS server does not point to the correct IP address.

The problem is that it is not alone there, there are other virtul hosts, too. The directory /etc/httpd/conf.d/ has files like these: 00-default.conf, vhost1.conf, vhost2.conf, etc., and one of these configuration files contains this WordPress multisite backup. Each of these virtual host configuration files look more or less the same:

<VirtualHost *:80>
  ServerName vhostX.example.org
  # rest of config goes here
</VirtualHost>

<VirtualHost *:443>
  ServerName vhostX.example.org
  # rest of config goes here
</VirtualHost>

The virtual host sections of the WordPress backup contain all the possible hostnames of the multisite in ServerAlias.

On my client, in the file /etc/hosts, I added the FQDN of the original machine to point to the IP address of the backup machine.

Now, the problem I observed, is as following:

  • Only the main website of the WordPress multisite instance is responding correctly, although it is also given as ServerAlias, not as ServerName.
  • All other domain names which are listed als ServerAlias are handled by the virtual host which is configured in 00-default.conf instead of the virtual host for the backup. This is the most annoying point I do not understand. Since the correct host name is given in the SNI as well as in the HTTP header, I expect it to pick up the correct the virtual host configuration because the domain name is listed there as ServerAlias.
  • If I replace *:80 and *:443 with the IP address notation, i.e. 192.168.1.2:80 resp. 192.168.1.2:443, then this WordPress backup is working, but nothing else anymore (I think everything is then handled by the WordPress multisite instance, which is configured to redirect to our main website then).

What I tried: The command on the client (host names and IP addresses redacted):

curl -vkLo- --resolve wpsite1.example.org:80:192.168.1.2 --resolve wpsite1.example.org:443:192.168.1.2 'http://wpsite1.example.org'

The file /etc/nsswitch.conf is set up to resolve the hosts file before querying the DNS server, if this is of any relevance. I also tried adding the IP address to the server's file /etc/hosts. As far as I understand, I assume that httpd tries to resolve the DNS names on startup, but since the DNS server resolves the name to the productive IP address, it does not work.

How can I solve this issue? Do I have to assign a second IP address to the host?

Score:0
jp flag

The next day, I found out the least obvious thing:

$ apachectl -S
[...]
141.201.80.66:80       is a NameVirtualHost
         default server one-of-the-wp-single-sites.example.org (/etc/httpd/conf.d/00_defaults.conf:1)
[...]

For some reason, it immediately came into my mind that this domain name is the first one with this IP address which is listed in the file /etc/hosts. Inserting the local host name in the file /etc/hosts before the other lines did the trick:

192.168.1.2   this-host.example.org

Reloaded Httpd, and everything was fine.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.