4

Google Client APIを使用して Symfony2 で記述された自分の Web サイトに Google サインインを実装しようとしています。ここの指示に従いましたが、 $client->authenticate($code); を呼び出すと、www.googleapis.com
ポート 443 への接続に失敗しました: ネットワークに到達でき
ません。何が問題なのですか?

4

5 に答える 5

7

解決策 2 (アップデートから)。これは ipv6 インターフェイスと php での curl のバグのようです。別の解決策は、curl 関数で適切なオプションを設定して、php スクリプトで ipv4 を使用してリモート サーバーに接続することです。

curl_setopt( $curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);


解決策 1.

同じことが私にも起こりました(ip v4とホスト名を /etc/hosts ファイルに追加することで解決しました)、別の回答コメントで@hans-zが指摘したように、次のコマンドを使用してネットワークの問題を検証しようとしました。

curl -v https://www.googleapis.com 

それはランダムであることが判明し、curlコマンドがサーバーに接続できたのは10回に1回だけで、応答は次のようなものでした:(「La red es inaccessible」は英語で「ネットワークに到達できない」を意味します:))

$ curl -v https://www.googleapis.com
* Rebuilt URL to: https://www.googleapis.com/
* Hostname was NOT found in DNS cache
*   Trying 64.233.186.95...
*   Trying 2800:3f0:4003:c00::5f...
* connect to 2800:3f0:4003:c00::5f port 443 failed: La red es inaccesible
* Failed to connect to www.googleapis.com port 443: La red es inaccesible
* Closing connection 0
curl: (7) Failed to connect to www.googleapis.com port 443: La red es inaccesible

そして、成功した応答は次のとおりです。

curl -v https://www.googleapis.com
* Rebuilt URL to: https://www.googleapis.com/
* Hostname was NOT found in DNS cache
*   Trying 64.233.186.95...
*   Trying 2800:3f0:4003:c00::5f...
* Connected to www.googleapis.com (64.233.186.95) port 443 (#0)
* successfully set certificate verify locations:
*   CAfile: none
  CApath: /etc/ssl/certs
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Server key exchange (12):
* SSLv3, TLS handshake, Server finished (14):
* SSLv3, TLS handshake, Client key exchange (16):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSL connection using ECDHE-RSA-AES128-GCM-SHA256
* Server certificate:
*    subject: C=US; ST=California; L=Mountain View; O=Google Inc; CN=*.storage.googleapis.com
*    start date: 2015-04-08 14:12:01 GMT
*    expire date: 2015-07-07 00:00:00 GMT
*    subjectAltName: www.googleapis.com matched
*    issuer: C=US; O=Google Inc; CN=Google Internet Authority G2
*    SSL certificate verify ok.
> GET / HTTP/1.1
> User-Agent: curl/7.35.0
> Host: www.googleapis.com
> Accept: */*
> 
< HTTP/1.1 404 Not Found
< Cache-Control: no-cache, no-store, max-age=0, must-revalidate
< Pragma: no-cache
< Expires: Fri, 01 Jan 1990 00:00:00 GMT
< Date: Tue, 21 Apr 2015 21:38:12 GMT
< Vary: X-Origin
< Content-Type: text/html; charset=UTF-8
< X-Content-Type-Options: nosniff
< X-Frame-Options: SAMEORIGIN
< X-XSS-Protection: 1; mode=block
* Server GSE is not blacklisted
< Server: GSE
< Alternate-Protocol: 443:quic,p=1
< Accept-Ranges: none
< Vary: Origin,Accept-Encoding
< Transfer-Encoding: chunked
< 
* Connection #0 to host www.googleapis.com left intact

奇妙なメッセージは「ホスト名が DNS キャッシュに見つかりませんでした」でした。Google DNS の 4.4.4.4 と 8.8.8.8 を使用していたので、curl コマンド出力の ipv4 を使用してそのドメインを /etc/hosts ファイルに追加し、問題を解決しました。解決しました。

#/etc/hosts
...
64.233.186.95 www.googleapis.com
#DONT COPY THIS IP, USE THE ONE FROM YOUR CURL OUTPUT
...
于 2015-04-21T21:49:35.740 に答える
3

ネットワークがプロキシの下にある場合。プロキシの URL とポートを設定する必要があります

curl_setopt($ch, CURLOPT_PROXY, "http://url.com"); //your proxy url
curl_setopt($ch, CURLOPT_PROXYPORT, "80"); // your proxy port number

これは私の問題を解決します

于 2016-07-21T06:16:42.787 に答える
0

同じ問題がありました-le0diazの回答で述べたように、問題はDNS解決にありました。

ubuntu 16.04 では、/etc/gai.conf を変更し、IPv6 の presedance を変更し、次の行のコメントを外すことで解決できました: precedence ::ffff:0:0/96 100

于 2017-10-19T10:20:47.290 に答える