Networking – Curl response hangs

curlnetworkingnginxvirtualbox

I have a site set up in a virtual box. I am able to access it just fine from a browser on my machine, but I have trouble accessing it via CURL while SSH'ed in to the box.

When I try, curl hangs before displaying the response and exiting.

This is what I run: curl -vvv site1.dev/

This is the output it gives:

* Hostname was NOT found in DNS cache
*   Trying 192.168.10.10...
* Connected to site1.dev (192.168.10.10) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.35.0
> Host: site1.dev
> Accept: */*
> 
< HTTP/1.1 200 OK
* Server nginx/1.9.7 is not blacklisted
< Server: nginx/1.9.7
< Content-Type: text/html; charset=UTF-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< Cache-Control: no-cache
< Date: Fri, 08 Apr 2016 16:47:30 GMT
< 
* Connection #0 to host site1.dev left intact
hi

The request portion is sent off right away, but the response hangs for a number of seconds (looks like 120ish), and then curl exits with that message: * Connection #0 to host site1.dev left intact

That is followed by the appropriate body of the response, "hi".

I'm a little lost — any pointers would be appreciated.

Edit April 11:
I've tried wget and see a similar result (response hangs). I suspect it is a network config issue.

In case it is relevant, here is some of the port config for the virtual box.

==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 80 => 8000 (adapter 1)
    default: 443 => 44300 (adapter 1)
    default: 3306 => 33060 (adapter 1)
    default: 5432 => 54320 (adapter 1)
    default: 22 => 2222 (adapter 1)

EDIT April 12:

So… I decided to destroy this vagrant box and start fresh…doing this has resolved the problem.

I suspect that I changed/broke something over the course of the past several months. Starting over, with the vanilla box settings, has corrected that problem.

Best Answer

Perhaps nginx is configured to do ip resolution of incoming requests and is taking time to resolve the incoming connection before actually answering the request.

A couple pointers though, you'll want to check the following on 192.168.10.10.

  1. Verify name servers are correct within /etc/resolv.conf
  2. If #1 resolv settings are are correct for primary and secondary nameservers, verify that 192.168.10.10 has the ability to resolve hosts. (simple nslookup to google.com is a good test for this, if timeout occurs then then this could be part of the issue)
  3. Ensure that your nginx server has the ability to query name servers externally or internally via firewall (port 53 tcp/udp)
  4. Look for potential resolver settings within nginx configuration options and or set resolution timeout setting where applicable and restart nginx.
  5. If its still an issue attempt to add the host of the incoming request connection within /etc/hosts on 192.168.10.10.

Let me know how that works for ya..

Thanks for posting.

Related Question