Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have a very low level question. I have several domains and would like to host them on a virtual server I've already set up. The server is running fine however I'm having trouble with the virtual hosting part. When I had only one domain up and running everything worked fine, now that I'm trying to add additional sites I've hit a wall.

I have this when I log on via terminal:

<VirtualHost *:80>

        ServerName www.mydomain1.com
        DocumentRoot /www/public_html/mydomain1.com/index.php

</virtualHost>

<VirtualHost *:80>

        ServerName www.mydomain2.com
        DocumentRoot /www/public_html/mydomain2.com/index.php

</virtualHost>

Now I have tried to modify these once I ran into trouble. My problem is now that I've tried so many things to get up and running, I can't get back to the beginning where everything worked.

share|improve this question

closed as too localized by Tom O'Connor, Bart De Vos, rnxrx, Ward, HopelessN00b Aug 29 '12 at 23:55

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

    
what is 'this'? Are you using apache? nginx? Is that the hhtpd.conf? –  Aaron Dec 16 '11 at 22:02
    
What actual problem are you having? –  Holocryptic Dec 16 '11 at 22:04
    
What happens when you try: apachectl -t From the cmd line? –  orbitron Dec 16 '11 at 22:22

2 Answers 2

Try putting NameVirtualHost *:80 at the beginning of the file.

Remove index.php from both DocumentRoot lines.

Then run apache2ctl restart. Try to access the sites, and if you get a 404 error, append index.php to the URL in the browser's address bar.

share|improve this answer

In the absence of more details, I'd agree with fuscata's advice (adding the NameVirtualHost directive and fixed the broken DocumentRoot directives).

To hopefully give you a bit more perspective on the name based virtual hosting setup, here's a short description of how it works. When you add "NameVirtualHost *:80" to the Apache configuration you're telling Apache to inspect the host header in the HTTP request in order to determine which set of configurations to apply to a particular request. The idea is that you can have many sites bound to the same IP (or IPs).

The ServerName directive in your virtual host containers will define a hostname-based set of configs, keyed off of the value passed into the Host: header on the request. So for example, for domain www.mydomain2.com above, you could have something like:

    <VirtualHost *:80>
        ServerName www.mydomain2.com
        ServerAlias mydomain2.com
        DocumentRoot /www/public_html/mydomain2.com/
        DirectoryIndex index.php index.html
    </virtualHost>

...where DocumentRoot points to the directory that represents the root level for the documents associated for the site, ServerAlias represents alternate ways to express the hostname (mydomain2.com, minus the 'www' for example). The DirectoryIndex directive defines which file(s) should be accessed for a root-level URI of "/" or none - for example, http://www.mydomain2.com.

Now all that said, if this is going to be a public facing site I strongly recommend that you spend time and learn how Apache works, and how to get a decent configuration up and running. It'll help you in the long run and it'll help you avoid security issues and other problems.

share|improve this answer

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