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.

Here is my apache default configuration for virtual host

<VirtualHost *:80>
ServerAdmin webmaster@localhost

DocumentRoot /var/www
<Directory />
    Options +FollowSymLinks
    AllowOverride None
</Directory>

<Directory "/var/www/mydir">
    AllowOverride FileInfo Limit Options Indexes
   </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 ${APACHE_LOG_DIR}/error.log

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

CustomLog ${APACHE_LOG_DIR}/access.log combined

This works well for http://mydomain.com but not for http://www.mydomain.com How to serve my domain with www ?

This problem is only for default domains, my other domains work for both with this config file

<VirtualHost *:80>
ServerName otherdomain.com
ServerAlias www.otherdomain.com
ServerAdmin webmaster@localhost

DocumentRoot /var/www/otherdomain

ServerSignature Off
<Directory />
    Options +FollowSymLinks
    AllowOverride None
</Directory>
<Directory /var/www/otherdomain>
    Options Indexes +FollowSymLinks MultiViews
    AllowOverride all
    Order allow,deny
    allow from all
</Directory>

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/otherdomain.com_access.log combined
ErrorLog /var/log/apache2/otherdomain.com_error.log
</VirtualHost>
share|improve this question
3  
What do you mean by "not working"? What do you expect to happen, what happens instead, and what do the logs say? –  Jenny D Feb 20 '13 at 13:04
    
If I access defaultdomain.com then browser shows "server not found" error. It works for defaultdomain.com –  atyagi Feb 21 '13 at 0:07
    
Maybe it is a stupid question, but...DNS record for www is properly configured? –  lg. Feb 21 '13 at 7:46

2 Answers 2

You have to tell apache the server names of each virtualhost using the ServerName and ServerAlias parameters.

Like:

<Virtualhost *:80>
    ServerName mydomain.com
    ServerAlias www.mydomain.com whatever.mydomain.com
    ...
</Virtualhost>
share|improve this answer
    
Please check default config file code, it has no ServerName <VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www .... serverAlias works for otherdomain config, but there is no servername in default so how to put serverAlias there? –  atyagi Feb 21 '13 at 0:09
    
besides the serverconfig, you also have to make sure that your DNS is pointing to the right IPs –  mauro.stettler Feb 21 '13 at 1:10
    
DNS is pointing to correct IP. It should be simple but seems I am missing something. All other domain urls are working with ServerName and ServerAlias but there is no ServerName in default config so I can not put any ServerAlias. Still thanks for your help. –  atyagi Feb 21 '13 at 6:06
1  
If this is the default domain, then all requests that don't match any other virtualhost will go to that domain by default, so in this particular case there's no need to enter any ServerAlias. –  Jenny D Feb 21 '13 at 7:31

If the response you get is "Server not found", then I'd lay a bet that there is something wrong with your DNS settings. Unfortunately since you've chosen to hide the actual domainname it's impossible for anybody here to help you figure out what that might be. However, here's a simple way to verify whether it is DNS or the apache config that's the problem

First, do nslookup www.yourdomain.com on the same machine that you're browsing from. Do you get an IP in return? If so, is it the one you'd expect?

Second, Instead of using a browser to the server, use telnet to talk directly to it. Like this:

[jenny@jennys:~]$ telnet your.server.ip.here 80
Trying your.server.ip.here...
Connected to your.server.name (your.server.ip.here).
Escape character is '^]'.
GET / HTTP/1.1
Host: www.yourdomainname.com

Make sure to press the Enter key twice after entering your domain name. Then post the output here.

share|improve this answer

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.