Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to use the DNS Alias to configure one of my domain pointing to a specific directory on the server.

Here is what I've done:

1) Change the IP address in domain setting, and it works

$ ping
PING ( 56 data bytes
64 bytes from icmp_seq=0 ttl=48 time=53.088 ms
64 bytes from icmp_seq=1 ttl=48 time=52.125 ms
--- ping statistics ---
2 packets transmitted, 2 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 52.125/52.606/53.088/0.482 ms

2) Add sites-available and sites-enabled

$ ls -l /etc/apache2/sites-available/
total 16
-rw-r--r-- 1 root root  948 2010-04-14 03:27 default
-rw-r--r-- 1 root root 7467 2010-04-14 03:27 default-ssl
-rw-r--r-- 1 root root  365 2010-06-09 18:27
$ ls -l /etc/apache2/sites-enabled/
total 0
lrwxrwxrwx 1 root root 26 2010-06-09 15:46 000-default -> ../sites-available/default
lrwxrwxrwx 1 root root 33 2010-06-09 18:17 -> ../sites-available/

But it doesn't work and when I open the browser for, it shows an 111 error:

The following error was encountered:
Connection to Failed
The system returned:
(111) Connection refused

Here is how's config:

$ cat /etc/apache2/sites-enabled/
<virtualhost *:80>
DocumentRoot "/vhosts/"
<Location />
    Order Deny,Allow
    Deny from None
    Allow from all
#Include /etc/phpmyadmin/apache.conf
ErrorLog /vhosts/
CustomLog /vhosts/ combined

Could you please tell me how to solve this?

share|improve this question
Are you able to connect to anything on that web server? Just to cover the basics... is Apache running? Port is open at the firewall for that IP? You can get a connection to port 80 on another IP on that box? – Justin Scott Jun 10 '10 at 6:57
I can access localhost, so I think the Apache is running – Johnny Jun 10 '10 at 10:21

This is the right name-based virtual host configuration.

NameVirtualHost *:80

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

<VirtualHost *:80>
ServerName www.otherdomain.tld
DocumentRoot /www/otherdomain
share|improve this answer

Try to add this row to the hosts file (/etc/hosts or C:\WINDOWS\System32\drivers\etc\hosts) in the client machine: www,

If, after restarting the browser, the site works the problem is DNS related, else the problem is apache related (check system and apache logs).

share|improve this answer
update hosts file and stays the same. And since I can ping the, will the DNS still a problem? – Johnny Jun 10 '10 at 8:37
No, I think DNS is not the problem. – lg. Jun 10 '10 at 9:55
Did you uncomment NameVirtualHost in apache conf? – lg. Jun 10 '10 at 9:58
where is the NameVirtualHost in config? – Johnny Jun 10 '10 at 10:21
Usually just above the virtual host settings. In Debian style you can find it in /etc/apache2/sites-available/default – lg. Jun 10 '10 at 10:32

I definitely feel that apache configuration might be the problem and not the dns. Your virtual host section says *:80. I hope you understand that. I think you already have a site running in that server on default port (80) . And you are trying to add another site to port 80. As you might know you cant have two process bind to the same port and same ip. If that is the problem then either bind to a non standard port and have user type the port in browser and connect or use a different ip to bind to instead of the all you have mentioned ( * == all). I have not have done name based virtual hosting, name based virtual hosting should also be a another alternative. Anyway your apache error log should clearly indicate what the problem is. The location of error log and access log should be mentioned in the master httpd.conf . Which is usually present in /etc/httpd/conf/httpd.conf and these virtual host conf's link from there. Having a error log and access log defined in virtual host section will also help in a big way to ease the trouble of finding what went wrong.

share|improve this answer

You have to do two thinks:

1) Set the hosts file. In Linux, there is /etc/hosts, in Windows in %WINDOWS%\System32\drivers\etc\hosts:

2) Set the Apache NamedVirtualHost in this way:


ServerAlias *
DocumentRoot /www/example

ServerAlias *
DocumentRoot /www/othersite

Edit 1: Notice 1: You can check, if Apache is listening on the all interfaces by this command:

netstat -tpln

If there will be a line like:

tcp      tcp        0    *               LISTEN

Then Apache is listening on every interfaces and everythink is OK. If there will be line like this:

tcp      tcp        0    *               LISTEN

Then Apache is listening only on the 'lo' interface, and there is a problem in the Apache's config files.


If Notice1 is OK, you have to check firewall by this way:

iptables -L -n

I know, that some RedHat clones have very strict firewall, that denied access to all ports except ssh... You can try to stop firewall and try, if you can connect to apache, and then control/add firewall rules...

share|improve this answer
As covered already, DNS is already setting the ip address, so why do you have the hosts file entry? – becomingwisest Jan 25 '12 at 12:52
Because Apache controls it and set according it the NamedVirtualHost entries. It's derived from my own experience - without this settings Apache didn't work and explain about it while startup. – Jan Marek Jan 25 '12 at 13:14
I could see maybe needing the hosts file entry by your use of VirtualHost, but if you have the ip address there you should not need the hosts entry. And using *:80 makes it so you don't need to know your ip address at all. – becomingwisest Jan 25 '12 at 15:12
Maybe there is one more reason - it's faster, because Apache don't need a DNS question/response, because it has record in the hosts file. – Jan Marek Jan 25 '12 at 21:09
Because when apache starts, it verify, if name is exactly on IP, on which is apache listening. – Jan Marek Jan 26 '12 at 8:01

Your Answer


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.