从AWS(PHP)查找IP访问

当您使用Amazon Server时,如果您获得了服务器IP,则会输出私有IP。
因此,我这样做是为了保存官方IP。
<?
if(in_array(substr($_SERVER['SERVER_ADDR'], 0, 3), array('172')))
if(strrpos(gethostname(), '.compute.internal')!==false)
$_SERVER['SERVER_ADDR'] = file_get_contents('http://169.254.169.254/latest/meta-data/public-ipv4');
echo $_SERVER['SERVER_ADDR'];
?>
Leave a Reply