Php

本地 php fopen 腳本在 CentOS 上返回 404 的問題

  • July 11, 2015

我今天在我們的伺服器上執行使用file_get_contents或類似fopen功能的 php 腳本時遇到了一些麻煩。我認為這是一個 openssl 或防火牆錯誤,但我對伺服器管理的東西還很陌生,所以我需要一些幫助來調試它。當它突然停止工作時,我正在修補iptablescsf firewall設置並嘗試使用它來配置 sftp 。proftpd

**一個簡單的測試:(**這個 gif 文件可以通過瀏覽器正常載入)

echo file_get_contents("https://www.this-domain.com/logo.gif");
//...failed to open stream:HTTP request failed! HTTP/1.1 404 Not Found...

//However both of the following work absolutely fine:
//a local request to the same file:
echo file_get_contents("/home/user/domains/this-domain.com/private_html/media/logospin.gif");
//an external absolute url:
echo file_get_contents("https://www.google.com/");

在 php.ini 中,我有:allow_url_fopen = on& extension=php_openssl.dllon。有任何想法嗎?

問題實際上是 DNS 問題。file_get_contents()出於某種原因,奇怪地通過我們的備用名稱伺服器(ns3 和 ns4)進行路由,而瀏覽器則通過主名稱伺服器(ns1 和 ns2)進行路由。與主文件不同,備份指向不同的伺服器,該伺服器還沒有相同的文件 - 因此出現不尋常的 404。

在修補防火牆等之前的幾個小時,我已經設置了這些備份名稱伺服器,當它們傳播時,它看起來非常像 ssh 命令已經file_get_contents()離線。

引用自:https://serverfault.com/questions/704964