file_get_contents-无法打开流:HTTP请求失败!找不到HTTP/1.1 404 [英] file_get_contents - failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
问题描述
将网站移至新域后,file_get_contents出现了一些奇怪的问题.我必须设置一个新的域和IP地址(使用Plesk)才能使用新的ssl证书.现在,我在同一个域上调用脚本的file_get_contents给了我这个:
I'm having some weird problems with file_get_contents after moving my site to a new domain. I had to set up a new domain and IP address (using Plesk) to get a new ssl certificate working. Now my file_get_contents calling a script on the same domain is giving me this:
无法打开流:HTTP请求失败!找不到HTTP/1.1 404
failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
如果我在另一台服务器上使用file_get_contents调用了相同的网址,则可以正常工作;如果我从失败的服务器上调用了www.google.com,则该网址仍然有效,因此,似乎只有在同一服务器上调用了url时, !
If I call the same url using file_get_contents on another server it works fine, and if I call www.google.com from the server thats failing that works, so it only seems to be if I call a url on the same sever!
我感觉到这可能与在一个服务器上拥有两个具有两个不同ssl证书的IP有关,当我从服务器获取服务器的file_get_contents/(索引页面)时,我得到plesk,这是一个新的域"页面,因此从本地服务器调用时,就像apache一样,它不会查找正确的虚拟主机.
I have a feeling it might have something to do with having two IPs with two different ssl certificates on the one server, when i file_get_contents / (index page) of the server from the server I get the plesk 'this is a new domain' page so its like apache isnt looking up the right virtual host when its called from its own sever.
要澄清(希望如此):
在托管域的服务器上:
file_get_contents('https://mydomain.com?limit=4&offset=0&s_date=2012-02-05&e_date=2012-03-13&order=release_date&dir=desc&cid=12');
给出无法打开流:HTTP请求失败!HTTP/1.1 404找不到"
gives "failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found"
file_get_contents('http://www.google.com');
正常工作
在另一台服务器上:
file_get_contents('https://mydomain.com?limit=4&offset=0&s_date=2012-02-05&e_date=2012-03-13&order=release_date&dir=desc&cid=12');
工作正常.
我尝试关闭ssl,但仍然遇到相同的问题.
I have tried turning ssl off and I still get the same problem.
推荐答案
当我在家中使用一台小型测试服务器时,我也遇到了这个问题.域名被解析为您的外部IP地址,并发送了一个请求.但是由于该请求来自您的网络内部,因此路由器无法将其识别为正常请求.它可能具有用于配置它的Web界面,并尝试从其自己的管理系统返回页面,然后在您指定的路径中找不到该页面.
I've had this problem too, when I working on a little test server at home. The domain name is resolved to your external IP address, and a request is sent. But because the request is coming from inside your network, the router doesn't recognise it as a normal request. It probably has a web interface for configuring it, and tries to return a page from its own management system, which is then not found at the path you specified.
在那种情况下,我在Windows PC上工作,可以通过将要测试的域添加到我的hosts
文件中,并指定127.0.0.1作为IP地址(或IP地址的IP地址)来解决该问题.服务器(如果它是同一网络中的另一台计算机).我认为在Linux中应该有一个类似的解决方案.
In that case, I was working on a Windows PC, and I could solve it by adding the domain I was testing to my hosts
file, specifying 127.0.0.1 as the IP-address (or the IP-address of the server, if it is another machine within the same network). In Linux there should be a similar solution, I think.
问题不是PHP或服务器,而是路由器.
The problem isn't PHP or your server, but your router.
这篇关于file_get_contents-无法打开流:HTTP请求失败!找不到HTTP/1.1 404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!