Apache name resolution is not working and I cannot figure out why

So I’ve got a Virtual machine running with a wordpress lamp stack running. I configured each with a separate folder /var/www/site1.com/ /var/www/site2.com/ and each with it’s own apache .conf file.

The site1.com.conf file is formatted as

<VirtualHost *:80>

	ServerAdmin admin@site1.com
	ServerName site1.com
	ServerAlias www.site1.com
	DocumentRoot /var/www/site1.com

	<Directory "/var/www/site1.com">
	     AllowOverride All
	</Directory>

	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

the second site is the same but site2.com in the .conf file. After enabling both sites and restarting apache I keep getting site2.com no matter what domain I use.I have dns resolution configured in pfsense to direct www.site1.com and www.site2.com to the ip of my virtual machine and it works as intended but I can’t access site1 without disabling site2 in apache. I thought this might possibly be a problem with the pfsense dns resolution so i switched the /etc/hosts file to point to my vm (which is running on another pc altogether) and I still only get site2. I’ve talked to google about it but I haven’t found a solution. Does anybody have any idea why name resolution isn’t working?

Why have you got two config files? There’s only one per server and it’s that where the two sites go. I always even in Windows only had one config file with multiple sites in it and I have run more than two that way. Have a look at this article it’s abit simplistic with what you can do with Apache but will point you in the right direction. How to configure multiple websites with Apache web server | Opensource.com

I’ll try using just one. The reason I have 2 config files is that it allows me to individually turn on/off each site with a2ensite a2dissite commands. I was following this tutorial: https://www.liquidweb.com/kb/configure-apache-virtual-hosts-ubuntu-18-04/ This is also how Jay describes setting up Apache in his book.

I just reviewed Jay’s book and his example does show one config file for name based resolution and multiple for ip resolution.

Have you done resolv.conf and then did a tinydns resolve sonit doesnt forward to your dhcp settings first and uses site1.com to your localhost 127.0.0.1:/site1.com aliased and masked to show site1.

I dont have a production setup to aid but thats where your messin up

So.you just use localhost and 127.0.0.1 or 192.168.0.1-254 on your router for thw layer of the networking stack you remember or think you want to use.

So I did a single .conf file and it made no difference. From everything that I’ve looked up I should be able to have separate configuration files for individual sites so that they can have their own settings and be separately enabled and disabled. Skraps I have my router dns resolving to my server with both site1.com and site2.com. But when I go to site1.com I get site2.com served to me. My apache server will not resolve the name. Is as far as I can tell eveything looks like it’s set up properly. I ran apache2ctl -S and it showed both virtual hosts with site2.com as the default. I was looking through the apache.org site and it says that for name-based virtual hosts to work it needs to use reverse DNS lookup. I haven’t found any settings for this yet and I’m assuming that’s what is giving me grief.

So if anyone is at all interested in what is going on here. I figured out what the problem was. It was a setting in wordpress. I hadn’t changed the site address url (DUH) which defaults to the local ip address. So when i would go to site1.com, wordpress would change the url to my local ip address and then apache would redirect to the default site which is site2.com. So I enabled each site individually and went in and changed the url to the site address in the wordpress settings. After enabling both sites again, name resolution is working perfectly. I was looking in the wrong in the wrong direction. I suppose if I would have looked at the address bar I would have clued in sooner. Thanks for the input anyway.

1 Like