curl:在不同的服务器上运行返回不同的 IP 地址

发布于 2024-12-22 03:56:26 字数 1268 浏览 0 评论 0原文

我一直在努力弄清楚为什么我的页面在 PHP 中使用 curl 库可以在我的开发机器上运行,但在我的远程服务器上失败。一种怀疑是它与 curl 是否具有 SSL 支持有关,如 这里的评论之一

如果你的curl安装没有使用SSL支持进行编译,当你试图找出为什么curl_exec()失败或执行其他任何操作时,你会用头撞墙......

所以,我运行了此脚本用于查明我的两台开发机器是否都支持 SSL和远程服务器。我的开发机器远程服务器都生成了以下内容(看起来都支持 SSL):

CURL_VERSION_IPV6 匹配 CURL_VERSION_KERBEROS4 不匹配 CURL_VERSION_SSL 匹配 CURL_VERSION_LIBZ 匹配

但是,当我从我的远程服务器(我的脚本失败的服务器)上的命令行运行 curl 时,这就是我的结果得到(即 curl 挂起):

curl -v http://<my-domain>/blog/press-release/
* About to connect() to <my-domain> port 80
*   Trying 66.201.45.235... 

相同的 curl 命令行运行良好我的开发机器虽然它返回了不同的IP地址:

curl -v http://<my-domain>/blog/press-release/
* About to connect() to <my-domain> port 80 (#0)
*   Trying 10.3.1.207... connected

请...请帮忙?还有其他方法可以找出我的开发计算机远程服务器上安装的curl之间的差异吗? 为什么他们返回不同的地址?

I've been struggling to figure out why my page which uses curl library in PHP worked on my dev machine but failed on my remote server. One suspicion is that it's related to whether the curl has an SSL support, as indicated in one of the comments here:

If your curl installation is not compiled with SSL support you will beat your head against a wall when trying to figure out why curl_exec() is failing to fail or do anything else ...

So, I ran this script to find out whether SSL is supported on both my dev machine and remote server. Both my dev machine and remote server produced the following (looks like both support SSL):

CURL_VERSION_IPV6 matches CURL_VERSION_KERBEROS4 does not match CURL_VERSION_SSL matches CURL_VERSION_LIBZ matches

However, when I ran curl from the command line on my remote server (the one where my script failed), here's what I got (i.e. curl hang):

curl -v http://<my-domain>/blog/press-release/
* About to connect() to <my-domain> port 80
*   Trying 66.201.45.235... 

The same curl command line worked fine on my dev machine although it returned a different IP address:

curl -v http://<my-domain>/blog/press-release/
* About to connect() to <my-domain> port 80 (#0)
*   Trying 10.3.1.207... connected

Please... please help? Any other way to figure out the differences between the installed curl on my dev machine and remote server? Why did they return different addresses?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

揪着可爱 2024-12-29 03:56:26

域名(如 my-domain.com)通过 解析为 IP 地址DNS

当程序尝试按名称访问网络设备时,操作系统会联系其配置的 DNS 服务器,并向其询问与所提供的名称相对应的 IP 地址。然后,DNS 服务器将返回一个 IP 地址(或一组 IP 地址 - 可以配置一个名称以解析为多个 IP 地址),或者返回一条错误消息,本质上是“我找不到该地址”姓名”。操作系统还将有一个 hosts 文件,它是域列表 -静态配置的到 IP 映射。如果主机文件中存在与请求的域匹配的内容,则不会联系 DNS 服务器,而是使用配置的 IP。

公司 LAN 通常有自己的内部 DNS 服务器来控制内部域,如果它收到对该域成员的请求,它将返回该主机的 LAN IP 地址,而不是 WAN IP 地址。

我对您的问题的猜测是发生了两件事之一:

  • 您的开发服务器上的主机文件有一个相关域的配置条目,该条目位于您的网络内部。我这样说是因为您在开发计算机上获得的地址解析为通常为 LAN 保留的范围内的 IP 地址
  • 您尝试联系的计算机位于您自己的域中,托管在您的开发计算机所在的网络内,并且您的 LAN 有一个控制您的域的 DNS 服务器,您的开发计算机使用该服务器进行 DNS 查找。

无论哪种方式,您需要解决的实际问题是您尝试联系的主机不接受来自 WAN 上 66.201.45.235 地址的连接,这是互联网看到的 IP 地址作为。这可能是由于服务器配置、防火墙、NAT 或许多其他因素之一造成的。

这不太可能与 SSL 相关 - cURL 正在尝试连接到端口 80,该端口用于未加密的 HTTP 连接,并且不需要 SSL。

您应该联系您的网络管理员来解决该问题。

A domain name (like my-domain.com) is resolved to an IP address through DNS.

When a program tries to access a network device by name, the operating system contacts it's configured DNS server and asks it for the IP address that corresponds to the supplied name. The DNS server will then either respond with an IP address (or set of IP addresses - it is possible to configure a name to resolve to more than one IP address) or an error message that says, in essence "I couldn't find that name". The operating system will also have a hosts file, which is a list of domain-to-IP mappings that are statically configured. If there is a match for the requested domain in the host file, the DNS server will not be contacted and the configured IP will be used instead.

A corporate LAN will often have it's own internal DNS server which controls an internal domain, and if it gets a request for a member of that domain, it will return the LAN IP address of that host, instead of the WAN IP address.

My guess for your problem is that one of two things is happening:

  • The hosts file on your dev server has a configured entry for the relevant domain, which is internal to you network. I say this because the address you get on your dev machine resolves to an IP address that lies in a range normally reserved for LANs
  • The machine you are trying to contact is on your own domain, hosted inside the network where your dev machine resides, and your LAN has a DNS server which controls your domain, used by you dev machine for DNS lookups.

Either way, the actual problem that you need to resolve is that the host you are trying to contact does not accept connections from the WAN on the 66.201.45.235 address, which is what the internet sees it's IP address as. This could be because of server configuration, firewalls, NAT or any one of a number of other things.

This is not likely to be anything SSL related - cURL is trying to connect to port 80, which is used for un-encrypted HTTP connections, and does not require SSL.

You should contact your network administrator to resolve the issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文