Curl works outside vm but not inside

痞子三分冷 提交于 2021-01-29 07:41:00

问题


I've tried the following:

Setting mtu to 1400

Downgrading vagrant to 1.8.7 and VirtualBox to 5.1.38

Turn off firewall on host (osx) and guest (Ubuntu)

Turn off iptables in guest os

Ping works, but anything that requires ssl handshake will fail including curl and file_get_contents in php times out

Examples:

vagrant@scotchbox:~$ openssl s_client -connect www.google.com:443 -prexit
CONNECTED(00000003)

But using curl:

vagrant@scotchbox:~$ curl -iv https://www.google.com
* Rebuilt URL to: https://www.google.com/
*   Trying 216.58.194.36...
* Connected to www.google.com (216.58.194.36) port 443 (#0)
* found 173 certificates in /etc/ssl/certs/ca-certificates.crt
* found 694 certificates in /etc/ssl/certs
* ALPN, offering http/1.1

It just hangs at this point.

PHP also has issues establishing handshakes:

Warning: file_get_contents(): SSL: Handshake timed out


回答1:


I stumbled at the same problem yesterday. I am now working back a HTTPS proxy with its own certificate. The host laptops are configured with this certificate but the VirtualBox guests are not. And this is valid for all guests. The solution is simple:

  1. Find and export the proxy's certificate in your HOST browser. I use Firefox and this is really simple
  2. Transfer the certificate file to the guest
  3. Run: sudo cp /etc/pki/ca-trust/source/anchors/
  4. And finally run: sudo update-ca-trust.

(I don't know the commands if you are running a Windows guest.)



来源:https://stackoverflow.com/questions/51603141/curl-works-outside-vm-but-not-inside

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!