Windows764bit, nginx1.5.8, php5.4.22, two virtual hosts, a.cn, B .cn {code...} on the virtual host B .cn, get the content of a file under a.cn through curl. The result page returns 504GatewayTime-out. There is a post on stackoverflow. I follow this post to do... windows 7 64bit, nginx 1.5.8, php 5.4.22, 2 virtual hosts, a.cn, B .cn
hosts:127.0.0.1 a.cn127.0.0.1 b.cn
On the VM B .cn, use curl to obtain the content of a file under a.cn.
Result page return504 Gateway Time-out.
There is a post on stackoverflow. I followed it, but it is still unsolved.
Http://stackoverflow.com/questions/9276114/php-curl-doesnt-see-the-etc-hosts
This is another post, but I have not solved the problem.
Http://stackoverflow.com/questions/3390549/set-curl-to-use-local-virtual-hosts
How can this problem be solved?
Previous Code (run in php on the command line. php test. php and test. php can return the following results)
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://a.cn' . '/u/ne.php'); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLINFO_HEADER_OUT, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $params); $data = curl_exec($ch); curl_close($ch); echo $data;
Code changed according to stackoverflow
$header = array( "Host: a.cn", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3", "Accept-Encoding: gzip,deflate,sdch", "Accept-Language: it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4", "Cache-Control: max-age=0", "Connection: keep-alive", ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://127.0.0.1' . '/u/ne.php'); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLINFO_HEADER_OUT, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $params); $data = curl_exec($ch); curl_close($ch); echo $data;
Reply content:
Windows 7 64bit, nginx 1.5.8, php 5.4.22, 2 virtual hosts, a.cn, B .cn
hosts:127.0.0.1 a.cn127.0.0.1 b.cn
On the VM B .cn, use curl to obtain the content of a file under a.cn.
Result page return504 Gateway Time-out.
There is a post on stackoverflow. I followed it, but it is still unsolved.
Http://stackoverflow.com/questions/9276114/php-curl-doesnt-see-the-etc-hosts
This is another post, but I have not solved the problem.
Http://stackoverflow.com/questions/3390549/set-curl-to-use-local-virtual-hosts
How can this problem be solved?
Previous Code (run in php on the command line. php test. php and test. php can return the following results)
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://a.cn' . '/u/ne.php'); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLINFO_HEADER_OUT, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $params); $data = curl_exec($ch); curl_close($ch); echo $data;
Code changed according to stackoverflow
$header = array( "Host: a.cn", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3", "Accept-Encoding: gzip,deflate,sdch", "Accept-Language: it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4", "Cache-Control: max-age=0", "Connection: keep-alive", ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://127.0.0.1' . '/u/ne.php'); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLINFO_HEADER_OUT, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $params); $data = curl_exec($ch); curl_close($ch); echo $data;
The code is correct after testing.
504 errors may occur on the web server. Use curl_error () to view the specific information.