Apache VirtualHost isn't serving a page
Solution 1:
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
Solution 2:
NameVirtualHost *:80
This is in /etc/apache2/ports.conf
. If you delete it or comment it out and restart Apache, the warning disappears.
Solution 3:
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.