I have two domains hosted on one server. I'm creating two files in /etc/httpd/conf.d
: first.conf
and second.conf
. Every file has the same content:
NameVirtualHost *
<VirtualHost *>
ServerName first.example.com
DocumentRoot /home/me/first
</VirtualHost>
When it's done I have a conflict. Only the second file works. All requests goes to /home/me/second
. No matter what domain I'm using. How to solve it? What am I doing wrong?
ps. It is very important for me to have many individual files, one per each domain name. And I should be able to easily remove any of them, without affecting others. And I don't want to touch default apache configs.. I think that it's possible to do the same without VirtualHost
, but some other instruction. I just can't remember its name.. :(
Put namevirtualhost in another config file, like apache(2).conf or httpd.conf (depending on your distro). On debian/ubuntu the right place would be the end of apache2.conf.
You only need nameVirtualHost once in your entire config.
Try to delete
NameVirtualHost
in second.confMove nameVirutual host out of the site configuration file. It belongs in the server configuation (apache.conf or http.conf).
Just to warn you. The first site will get any requests not covered by virtual hosts. This is your default server. You may want to configure an extra site to handle this case.
I'm pretty sure the
Include
directive reads files from the conf.d directory in alphabetical order. If you can come up with a naming convention for the files that ensured the desired order, you could addNameVirtualHost *
to a single file: perhaps something like '__NameVirtualHost.conf' or something. This would enable you to remove any of the individual VirtualHost files without affecting the others as desired.You could probably also tweak your file generation to generate a single file rather than multiple files (after all, they could just be concatenated together for equivalent functionality). Assuming that when a virt host is deleted it is being deleted at source, and the file set regenerated?
How are you accessing the server, over the hostname?
Also, your file shows first.example.com, I assume the second one has second.example.com. Could you post the full contents of the second file?