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 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 www.example.com
PING example.com (124.205.62.xxx): 56 data bytes
64 bytes from 124.205.62.xxx: icmp_seq=0 ttl=48 time=53.088 ms
64 bytes from 124.205.62.xxx: icmp_seq=1 ttl=48 time=52.125 ms
^C
--- example.com 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 example.com
$ 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 001-example.com -> ../sites-available/example.com

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

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

Here is how example.com's config:

$ cat /etc/apache2/sites-enabled/001-example.com
<virtualhost *:80>
DocumentRoot "/vhosts/example.com/htdocs/"
ServerName www.example.com
ServerAlias example.com
<Location />
    Order Deny,Allow
    Deny from None
    Allow from all
</Location>
#Include /etc/phpmyadmin/apache.conf
ErrorLog /vhosts/example.com/logs/error.log
CustomLog /vhosts/example.com/logs/access.log 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

4 Answers 4

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>

<VirtualHost *:80>
ServerName www.otherdomain.tld
DocumentRoot /www/otherdomain
</VirtualHost>
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:

124.205.62.48 www,example.com

If, after restarting the browser, the site www.example.com 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 www.example.com, 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:

124.205.62.48 www.example.com www.othersite.com

2) Set the Apache NamedVirtualHost in this way:

NameVirtualHost 124.205.62.48:80

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

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

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      0.0.0.0:80              0.0.0.0:*               LISTEN

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

tcp      tcp        0      127.0.0.1:80              0.0.0.0:*               LISTEN

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

Notice2:

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 www.example.com:80, 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
1  
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

 
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.