Nginx和PHP-cgi - 不能在服务器上的任何网站的file_get_contents [英] Nginx and PHP-cgi - can't file_get_contents of any website on the server

查看:419
本文介绍了Nginx和PHP-cgi - 不能在服务器上的任何网站的file_get_contents的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是最好的解释代码我认为。从网络目录:

This one is best explained by code I think. From the web directory:

vi get.php

将此php添加到get.php

Add this php to get.php

<?
echo file_get_contents("http://IPOFTHESERVER/");
?>

IPOFTHESERVER是运行nginx和PHP的服务器的IP。

IPOFTHESERVER is the IP of the server that nginx and PHP are running on.

php get.php

返回托管在该IP的(默认)网站的内容但

Returns the contents of the (default) website hosted at that I.P. BUT

http://IPOFTHESERVER/get.php

..返回 504网关超时。它和curl一样。使用PHP exec命令和GET也是一样。然而,从命令行直接它一切工作正常。

..returns a 504 Gateway Time-out. It's the same with curl. It's the same using the PHP exec command and GET. However, from the command line directly it all works fine.

我已在2个nginx服务器上复制它。由于某种原因,nginx不允许我通过PHP(除非通过命令行)与运行的服务器建立HTTP连接。

I've replicated it on 2 nginx servers. For some reason nginx won't allow me to make an HTTP connection to the server its running on, via PHP (unless it's via the command line).

任何人都有任何想法为什么?

Anyone got any ideas why?

谢谢!

推荐答案

检查你的PHP没有进入工作区耗尽,这是我的实验室服务器设置的问题,被配置为保存RAM。

Check that your not running into worker depletion on the PHP side of things, this was the issue on my lab server setup which was configured to save RAM.

基本上我忘了你使用单个工作程序来处理主页面已经显示给最终用户,然后get_file_contents()函数基本上是生成一个单独的HTTP请求到同一个Web服务器,有效地需要2个工作单一页面加载。

Basically I forgot that your using a single worker to process the main page been displayed to the end-user, then the get_file_contents() function is basically generating a separate HTTP request to the same web server, effectively requiring 2 workers for a single page load.

由于第一页使用的是最后一个工作,因此没有可用的get_file_contents函数,因此Nginx最终回复了504因为没有对反向代理请求的回复。

As the first page was using the last worker there was none avaliable for the get_file_contents function, therefore Nginx eventually replied with a 504 on the first page because there was no reply on the reverse proxy request.

这篇关于Nginx和PHP-cgi - 不能在服务器上的任何网站的file_get_contents的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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