This article is a mirror article of machine translation, please click here to jump to the original article.

View: 13699|Reply: 0

[Web] nginx proxy mode, obtain the real IP address of the client

[Copy link]
Posted on 11/3/2014 9:48:11 AM | | |
Recently, I was recommended by a blogger, and I found a small problem, so I used $_SERVER['REMOTE_ADDR']; I got the server address 192.168.96.52, searched it, found the problem, and changed it to $_SERVER['HTTP_X_REAL_IP']; :
nginx proxy mode, obtain the real IP address of the client
Set in nginx:

proxy_set_header        Host            $host;
proxy_set_header        X-Real-IP       $remote_addr;
proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;

The backend program can obtain the user's IP address from the Server variable HTTP_X_REAL_IP and HTTP_X_FORWARDED_FOR.

The value of HTTP_X_REAL_IP is the user REMOTE_ADDR that nginx gets





Previous:Nginx on the front-end and Apache on the back-end obtain the user's real IP address
Next:The front-end nginx and back-end nginx server records the IP address of the original client
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com