Nginx代理传递连接超时到HHVM

I am having a very weird problem. I have my servers connecting to my api via proxypass.

server {
    listen   80;
    server_name  www.example.com;

    location / {
        root    /data/sites/www.example.com/public_html/;
        index  index.php index.html index.htm;
        try_files $uri $uri/ /index.php?rt=$uri&$args;
    }

    location /api {
        proxy_pass_header  Set-Cookie;

        proxy_pass_header  P3P;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Fowarded-Host $host;
        proxy_set_header   X-Real-IP $remote_addr;
        port_in_redirect off;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        proxy_pass https://api.example.com/;
        proxy_connect_timeout 60;
    }

    location ~ \.php$ {
        root    /data/sites/www.example.com/public_html/;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index  index.php;
        #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        fastcgi_param  PATH_INFO        $fastcgi_path_info;
        fastcgi_param  ENV  production;
        fastcgi_param HTTPS off;
        fastcgi_read_timeout 300;
    }

}

So the url www.example.com/api is a proxy pass to api.example.com . But the connection always timeouts. Now if I go to api.example.com directly in my browser, it WORKS!

So I'm baffled. Anyone have any ideas what could be going on?

If api.example.com is a DNS name and not an upstream label, you may need to add a resolver statement to give nginx access to DNS.

resolver 8.8.8.8;
proxy_pass https://api.example.com/;

See this document for details.