Apache Config for Virtual Hosts by Name on One IPv4 IP

Issues related to applications and software problems
Post Reply
CharlieSummers
Posts: 3
Joined: 2017/08/27 20:19:17

Apache Config for Virtual Hosts by Name on One IPv4 IP

Post by CharlieSummers » 2017/08/27 20:28:54

I am having something of a time; this all started when I wanted to install Let's Encrypt certificates, and I eventually got things so fouled up I needed to uninstall/reinstall Apache and dependencies to get default config files, and am pulling out most of what little hair I have left. Running CentOS release 6.9 (Final), Apache 2.2.15-60 on a leased virtual server for a handful of low-bandwidth websites.

In the old days, when everything was in http.conf and Apache was young, it looked like:

Code: Select all

NameVirtualHost 1.2.3.4

<VirtualHost 1.2.3.4>
ServerName www.domain.tld
---other stuff---
</VirtualHost>

<VirtualHost 1.2.3.4>
ServerName www.seconddomain.tld
---other stuff---
</VirtualHost>
Now IPs and ports need to be listed, and the domain config has been removed to /etc/http/conf.d. I know it SHOULD look something like:

Code: Select all

http.conf unremmed:
NameVirtualHost *:80

www.domain.tld.conf:
<VirtualHost *:80>
ServerName www.domain.tld
---other stuff---
</VirtualHost>

www.seconddomain.tld.conf:
<VirtualHost *:80>
ServerName www.seconddomain.tld
---other stuff---
</VirtualHost>
...but that throws errors about no NameVirtHost directive, and causes all of the sites to resolve to whatever shows up first. I tried:

Code: Select all

<VirtualHost 1.2.3.4:80>
--and--
<VirtualHost *:80>
...but that causes errors about the virtual hosts being duplicated.

To finally fix this, I had to move the NameVirtHost directive in http.conf to ABOVE the "Include conf.d/*.conf" line (in the default file, it is well below), and cause each of the domains to look like:

Code: Select all

www.domain.tld.conf:
<VirtualHost www.domain.tld:80>
ServerName www.domain.tld
---other stuff---
</VirtualHost>

www.seconddomain.tld.conf:
<VirtualHost www.seconddomain.tld:80>
ServerName www.seconddomain.tld
---other stuff---
</VirtualHost>
This works ok, and doesn't cause errors in restarting Apache, but it's...odd, and just doesn't seem right to me. Before I even try to install any SSL, I'd like to get THIS mess cleaned up.

So...is this how things should look? Is this a valid configuration for name-based hosts? Will it all blow up when I try running certbot to get SSL certificates?



Edit: Turn off AutoParse URIs. Oops.

Post Reply