Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have an ubuntu server running apache on localhost / port 80. It's domain is sub.domain.com

If I make a curl request to http://localhost on that machine it will error with 'couldnt connect to host' immediately.

If I make a curl request to sub.domain.com on that machine it will sit there in an infinite loop until it times out after a few minutes.

If I open sub.domain.com in my web browser on another machine it shows my html page.

If I make a curl request to sub.domain.com with another machine it will connect.

What's the deal here?

share|improve this question
    
What does your /etc/hosts file look like on the server? Can you add it to the question. And check that /etc/nsswitch.conf has hosts: files dns somewhere (unless you know that it should be different). –  webtoe Apr 17 '12 at 16:32
    
What does netstat -anp|grep :80|grep Listen say? Does your apache only listen on specific IPs, but not on 0.0.0.0 or 127.0.0.1 specifically? –  arjarj Apr 17 '12 at 16:49
    
it listens on 192.168.2.1 and then a public IP. loopback device is 127.0.0.1 –  Ashley Smith Apr 17 '12 at 17:57
add comment

3 Answers

up vote 1 down vote accepted

Your comment: "it listens on 192.168.2.1 and then a public IP. loopback device is 127.0.0.1". So, Apache isn't listening on 127.0.0.1? If that's the case, that is your problem. Configure Apache to listen to all interfaces, or at least add the loopback interface to what Apache is listening on.

Next issue: "If I make a curl request to sub.domain.com on that machine it will sit there in an infinite loop until it times out after a few minutes." What do you get when you ping sub.domain.com? This issue feels like a name resolution problem on that machine, as you're able to connect successfully from another machine.

share|improve this answer
add comment

You likely need to specify the host headers using curl or else Apache doesn't know what page to display - depending on how you are set up localhost will probably show an apache default page, while your virtual host (sub.domain.com) will show the page you expect.

Try using:

curl -H "Host:sub.domain.com" 127.0.0.1
share|improve this answer
    
That gives me a curl error: couldn't connect to host. –  Ashley Smith Apr 17 '12 at 16:18
add comment

Do ping sub.domain.com from another machine and record ip address in responses (xxx.yyy.zzz.www). Then from apache machine use:

curl -H "Host:sub.domain.com" xxx.yyy.zzz.www
share|improve this answer
    
Gives me 192.168.2.1. The loopback device is 127.0.0.1. Still timed out. –  Ashley Smith Apr 17 '12 at 17:54
    
Odd. I would check firewall on apache machine next. –  dusan.bajic Apr 17 '12 at 18:13
add comment

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.