2016-10-18 7 views
0

私は非常に奇妙な問題が発生しています。私は自分のサーバーをproxypass経由で私のapiに接続しています。Nginx Proxy Pass接続がタイムアウトしましたHHVM

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; 
    } 

} 

したがって、URL www.example.com/apiは、api.example.comへのプロキシパスです。しかし、接続は常にタイムアウトします。今すぐ私のブラウザで直接api.example.comに行くと、それは働く!

私はうんざりです。誰でも何が起こっているのか考えていますか?

答えて

0

api.example.comがDNS名で、upstreamラベルではない場合、nginxにDNSにアクセスするには、リゾルバーステートメントを追加する必要があります。

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

詳細については、this documentを参照してください。