Nginx reverse proxy is a common function of the process of Web layout. After setting the reverse proxy, by reading the HTTP header inside the REMOTE_ADDR can not get the true user IP, we need to increase the nginx configuration to solve this problem.
The following is an experiment to illustrate.
Configure 1 Nginx servers and configure 3 domain names: t2.guokai.work, Tt2.guokai.work, Ttt2.guokai.work.
In the Nginx configuration, when accessing T2.guokai.work, the agent forwards to the Tt2.guokai.work, which is then forwarded to Ttt2.guokai.work by the tt2.guokai.work agent.
In the configuration of T2.guokai.work and Tt2.guokai.work, a key configuration needs to be added:
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
# Proxy_pass Http://tt2.guokai.work; #//t2.guokai.work configuration
proxy_pass http://ttt2.guokai.work; #//Tt2.guokai.work Configuration
Where the Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for refers to the x-forwarded-for that adds "To whom to forward" append to the HTTP header during the forwarding process. Each time forwarding, as long as there is this sentence configuration, will be the previous IP write to the X-forwarded-for field, if there is already this field, then separated by commas.
Look at the effect of the test:
ttt2.guokai.work/index.php
foreach ($_server as $key => $val) {
echo $key. " ---> ". $val." <br/> ";
}