6

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:

NameVirtualHost 192.168.10.151:80

My sites-available/www.mydomain.com is:

Listen 80
<VirtualHost *>
        ServerAdmin     [email protected]
        ServerName      www.mydomain.com
        ServerAlias     mydomain.com

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

        # Log Files
        ErrorLog        /media/BigDisk/www/www.mydomain.com/logs/error.log
        CustomLog       /media/BigDisk/www/www.mydomain.com/logs/access.log combined
</VirtualHost>

And the site was enabled using a2ensite and apache reloaded without any warnings or errors, but when I go to www.mydomain.com 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 127.0.1.1 for ServerName
[Thu Sep 01 12:16:22 2011] [warn] NameVirtualHost 192.168.10.151:80 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 127.0.1.1 for ServerName
[Thu Sep 01 12:16:22 2011] [warn] NameVirtualHost 192.168.10.151:80 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 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs
Action 'start' failed.
The Apache error log may have more information.

3 Answers 3

5

Check Name Resolution

First use nslookup or dig or host to check that www.mydomain.com 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 www.mydomain.com, you can add 192.168.10.151 www.mydomain.com 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.


Update:

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

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:

Wget

Another good diagnostic tool is to run this on the server

 wget --header="Host: www.mydomain.com" -O - http://localhost

This is the sort of output you should see

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

 0% [                                       ] 0           --.-K/s              <html>
 <head>
  <title>mybox</title>
 </head>
 <body>
  <h1>mybox</h1>
  <p>Nothing to see, move along</p>
 </body>
</html>
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
127.0.0.1 - - [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.

Netstat

The output from netstat -anp should include

tcp        0      0 :::80        :::*       LISTEN      12345/httpd
10
  • 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, 2011 at 13:21
  • Answer updated. Sep 1, 2011 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, 2011 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? Sep 1, 2011 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, 2011 at 15:29
1
NameVirtualHost  *:80

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

1

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.

You must log in to answer this question.

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