Super User is a question and answer site for computer enthusiasts and power users. 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 have a domain name that is linked to my ip address at home. However, I want to use the same server/ip to show more than one website.

I can't get Virtual Hosts to work though.

My conf.d/virtual.conf is:


My sites-available/ is:

Listen 80
<VirtualHost *>

        #Indexes and Directory Root
        DirectoryIndex  index.html index.php
        DocumentRoot    /media/BigDisk/www/

        # Log Files
        ErrorLog        /media/BigDisk/www/
        CustomLog       /media/BigDisk/www/ combined

And the site was enabled using a2ensite and apache reloaded without any warnings or errors, but when I go to I don't get anything ("Opps! Google Chrome could not connect...").

What am I doing wrong?

Update: Restarting Apache results in this:

malfist@webhost:~$ sudo /etc/init.d/apache2 restart
[sudo] password for malfist:
 * Restarting web server apache2                                                                                                                       apache2: Could not reliably determine the server's fully qualified domain name, using for ServerName
[Thu Sep 01 12:16:22 2011] [warn] NameVirtualHost has no VirtualHosts
[Thu Sep 01 12:16:22 2011] [warn] NameVirtualHost *:80 has no VirtualHosts
apache2: Could not reliably determine the server's fully qualified domain name, using for ServerName
[Thu Sep 01 12:16:22 2011] [warn] NameVirtualHost has no VirtualHosts
[Thu Sep 01 12:16:22 2011] [warn] NameVirtualHost *:80 has no VirtualHosts
(98)Address already in use: make_sock: could not bind to address
no listening sockets available, shutting down
Unable to open logs
Action 'start' failed.
The Apache error log may have more information.
share|improve this question
up vote 3 down vote accepted

Check Name Resolution

First use nslookup or dig or host to check that points at the static external IP-address of your router.

Check router config

Then check that your router has port forwarding configured so that requests arriving on port 80 at the external interface are forwarded to port 80 at your server's private IP address.

Check ISP restrictions

Then check that your ISP's Terms and Conditions allow for you to run a HTTP service. Some ISPs block inbound HTTP connections.

LAN != Internet

Lastly, remember that if you are testing this from within your LAN you need a different IP-address for, you can add to your hosts file (e.g. /etc/hosts or C:\WINDOWS\system32\drivers\etc\hosts). As Malfist pointed out in a comment: if the router supports NAT-reflection, this is not be necessary.


Check the Apache error logs (all of them)

"Could not connect" suggests a basic IP connectivity problem rather than an Apache vhost configuration problem. The latter is more likely to result in a HTTP response of 404 or 500. If the request reached Apache you should see an entry in the error log. If there is no entry there, it is a good indicator that Apache isn't receiving any request.

Follow up warnings and errors reported by Apache

NameVirtualHost *:80 has no VirtualHosts

See common misconfigurations

Multiple NameVirtualHost lines will yield a "NameVirtualHost *:80 has no VirtualHosts" warning. Apache will ignore the second directive and use the first defined NameVirtualHost line, though. This seems to happen when one is using multiple virtual host configuration files and doesn't understand that you only need to define a particular NameVirtualHost line once. As above, this can occur in the debian ports.conf file, especially after an upgrade.

Address already in use: make_sock: could not bind to address

Some other program is already listening on port 80. Use netstat -anp to find out what, then stop it.

Diagnostic tools

Ethernet Sniffer

I would use a network sniffer (e.g. tcpdump or wireshark) on the Apache server to see what incoming HTTP requests are arriving - if none, then you know it's an IP connectivity problem.

Update 2:


Another good diagnostic tool is to run this on the server

 wget --header="Host:" -O - http://localhost

This is the sort of output you should see

[root@mybox logs]# wget --header="Host:" -O - http://localhost
--2011-09-01 18:56:08--  http://localhost/
Resolving localhost...
Connecting to localhost||:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 125 [text/html]
Saving to: `STDOUT'

 0% [                                       ] 0           --.-K/s              <html>
  <p>Nothing to see, move along</p>
100%[======================================>] 125         --.-K/s   in 0s

2011-09-01 18:56:08 (10.8 MB/s) - `-' saved [125/125]

[root@mybox logs]# tail -n 1 access_log - - [01/Sep/2011:18:56:08 +0100] "GET / HTTP/1.0" 200 125 "-" "Wget/1.11.4 Red Hat modified"

Add the -S option to wget to see the server's response headers.

If you get something like "connection refused", Apache isn't listening on port 80.


The output from netstat -anp should include

tcp        0      0 :::80        :::*       LISTEN      12345/httpd
share|improve this answer
My router supports NAT reflection, so I can point to my public IP and the router has no problem. The DNS entry for the domain is correct, and my ISP doesn't care. I was running fine (single domain on laptop) until I decided to do Virtual Hosts, and now it's not working. – Malfist Sep 1 '11 at 13:21
Answer updated. – RedGrittyBrick Sep 1 '11 at 14:00
I run a different version of chrome at work, and it gives the error message, "tcp_error", and "connection refused". Does that clarify anymore? I know the IP/DNS entry is correct, because I have port 8080 routed to another box inside the LAN, and I can reach it just fine. – Malfist Sep 1 '11 at 15:21
"connection refused" suggests a problem in your router configuration. If Apache is configured normally and is listening on port 80, your server won't refuse connections. Have you checked the error logs and used a network sniffer as I suggested? – RedGrittyBrick Sep 1 '11 at 15:27
The router allowed the connection until I switch apache to virtual hosts, and if I switch apache's configuration back, the page resolves successfully. – Malfist Sep 1 '11 at 15:29
NameVirtualHost  *:80

This is in /etc/apache2/ports.conf. If you delete it or comment it out and restart Apache, the warning disappears.

share|improve this answer

I spent hours on this and all I needed to do is release my ip address ifconfig eth0 down. It became static, now it recognizes my virtual host name.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .