7

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?

3
  • 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, 2012 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, 2012 at 16:49
  • it listens on 192.168.2.1 and then a public IP. loopback device is 127.0.0.1 Apr 17, 2012 at 17:57

3 Answers 3

4

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.

6

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
1
  • That gives me a curl error: couldn't connect to host. Apr 17, 2012 at 16:18
1

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
2
  • Gives me 192.168.2.1. The loopback device is 127.0.0.1. Still timed out. Apr 17, 2012 at 17:54
  • Odd. I would check firewall on apache machine next. Apr 17, 2012 at 18:13

You must log in to answer this question.

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