Home  >  Article  >  Backend Development  >  nginx使用rewrite重定向,再在跳转到的服务器获取nginx服务器ip

nginx使用rewrite重定向,再在跳转到的服务器获取nginx服务器ip

WBOY
WBOYOriginal
2016-06-06 20:17:011525browse

问题如题,使用如下代码,跳转至指定的服务器

<code>            rewrite ^/(.*)$ http://xxxx.cn/index.php?id=/$1 permanent;                         </code>

现在,想在跳转到的服务器在获取这个nginx服务器的ip地址,使用PHP,常用的获取代码似乎获取不到,求教是否有办法能够获取到?

$ip = $_SERVER["REMOTE_ADDR"];
echo $ip;
?>

回复内容:

问题如题,使用如下代码,跳转至指定的服务器

<code>            rewrite ^/(.*)$ http://xxxx.cn/index.php?id=/$1 permanent;                         </code>

现在,想在跳转到的服务器在获取这个nginx服务器的ip地址,使用PHP,常用的获取代码似乎获取不到,求教是否有办法能够获取到?

$ip = $_SERVER["REMOTE_ADDR"];
echo $ip;
?>

nginx的rewrite是一个http重定向,通知浏览器请求新的地址,你可以通过cookie或者url来传递你需要的参数到跳转到的服务器。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn