2

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.. :(

  • Seriously, you will make things way easier on yourself if you just add the one line NameVirtualHost * to the main Apache config file (httpd.conf or whatever). – David Z Jul 27 '10 at 20:31
5

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.

  • I have a feeling that I can do the same thing, but without VirtualHost command... – yegor256 Jul 27 '10 at 17:42
  • You want virtualhosts without the <virtualhost> directive? You could do that with some pretty complicated rewrite rules, provided you load mod_rewrite. – Jasper Jul 27 '10 at 19:14
0

Try to delete NameVirtualHost in second.conf

  • I can't, I need my files to be of the same format. I generate them automatically and they don't know anything about each other. Any one may be deleted occasionally. – yegor256 Jul 27 '10 at 16:14
0

Move 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.

0

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 add NameVirtualHost * 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?

0

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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.