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?

Ashley Smith
  • 73
  • 1
  • 1
  • 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 '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

3 Answers3

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
WerkkreW
  • 5,879
  • 3
  • 23
  • 32
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.

cjc
  • 24,533
  • 2
  • 49
  • 69
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
Dusan Bajic
  • 2,046
  • 1
  • 17
  • 20