curl:在不同的服务器上返回不同的IP地址 [英] curl: Ran on Different Servers Returned Different IP Addresses

查看:606
本文介绍了curl:在不同的服务器上返回不同的IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力弄清楚为什么我在PHP中使用 curl 库的页面在我的 dev机器上工作 em>远程服务器。一个怀疑是,它与 curl 是否具有SSL支持相关,如此处的评论


如果您的curl安装不是编译时使用SSL支持,当你试图找出为什么curl_exec()没有失败或者做任何其他事情时,你会打败你的头...


因此,我运行此脚本来查找检查我的 dev机器远程服务器是否支持SSL。我的 dev计算机远程服务器生成以下(看起来都支持SSL):


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


但是,当我运行 curl 从我的远程服务器上的命令行(我的脚本失败的那个),这是我得到的(即 curl hang):

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

同样 curl 命令行在我的 dev机器上工作正常,尽管它返回了不同的IP地址:

  curl -v http://< my-domain> / blog / press-release / 
*关于to()到< my-domain>端口80(#0)
*尝试10.3.1.207 ...已连接

.. 请帮忙?以任何其他方式找出在我的 dev机器远程服务器上安装的 curl 之间的区别吗? 为什么返回不同的地址?

解决方案

my-domain.com )通过 DNS 解析为IP地址。



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



企业局域网通常有自己的内部DNS服务器来控制内部域,如果它收到该域成员的请求,它将返回LAN IP地址。



我猜你的问题是发生了两件事情之一:




  • 您的开发服务器上的主机文件具有相关域的配置条目,这是您网络的内部。我说这是因为你在你的开发机器上得到的地址解析为通常为LAN保留的IP地址

  • 您尝试联系的机器在您自己的域上,托管在您的开发机所在的网络内部,并且您的LAN具有控制您的域的DNS服务器,由您的开发机用于DNS查找。



无论哪种方式,您需要解决的实际问题是您尝试联系的主机不接受来自WAN上 66.201.45.235 地址的连接,这是互联网看到的IP地址。这可能是因为服务器配置,防火墙,NAT或任何其他一些事情。



这不可能是任何SSL相关的 - cURL正试图连接到端口80,该端口用于未加密的HTTP连接,并且不需要SSL。



您应该与您的网络管理员联系以解决此问题。 >

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?

解决方案

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.

这篇关于curl:在不同的服务器上返回不同的IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆