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 setup a server with Ubuntu 10.04 server edition. It's works for a long time with a single domain name. Now i want to add another domain wich will pointed to a new directory.

I tried to change my Apache2 configuration but it does not seems to work properly.

Here is my /etc/apache2/sites-available/default

<VirtualHost *:80>
DocumentRoot /var/www/
<Directory />
    Options FollowSymLinks
    AllowOverride None
</Directory>
<Directory /var/www/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
    AllowOverride None
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
</Directory>

ErrorLog /var/log/apache2/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog /var/log/apache2/access.log combined

Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
    Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>

</VirtualHost>

<VirtualHost *:80>
ServerName mydomain.com
ServerAlias www.mydomain.com
DocumentRoot /var/www/mydomain
</VirtualHost> 

here is my /etc/hosts

127.0.0.1 localhost

**.***.133.29   sd-***.****.fr sd-****
**.***.133.29   mediousgame.com

 # The following lines are desirable for IPv6 capable hosts 
 ::1     localhost ip6-localhost ip6-loopback
 ****::0 ip6-localnet
 ****: :0 ip6-mcastprefix
 ****::1 ip6-allnodes
 ****::2 ip6-allrouters
 ****::3 ip6-allhosts

With this configuration when i try to access to mydomain it redirect to the /var/www/ content. Do you have any idea to redirect to the right folder ?

share|improve this question

1 Answer 1

If you look at the following example taken from apache doc, it seems you are missing ServerName line from the first virtual host. Try to make your configuration similar to this (of course, you can keep the other directives like <directory>).

NameVirtualHost *:80

<VirtualHost *:80>
ServerName www.domain.tld
ServerAlias domain.tld *.domain.tld
DocumentRoot /www/domain
</VirtualHost>

<VirtualHost *:80>
ServerName www.otherdomain.tld
DocumentRoot /www/otherdomain
</VirtualHost>

Don't forget to setup the right DNS entries or at least modify your hosts file to resolve both domains to the correct IP address.

share|improve this answer
    
My first Virtualhost don't have any name, it show some content after redirection... Just added my /etc/hosts –  x_vi_r Sep 3 '12 at 14:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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