Preface There are two types of nginx modules, official and third-party. We use the command nginx -V to view the nginx installation information, and we can see the following module information about the --with nginx startup loading. realip module Purpose: When the local Nginx is in the reverse proxy backend, the user's real IP address can be obtained. Usage: The realip function requires Nginx to add the ngx_http_realip_module module, which is not compiled by default. If you need to add it, please add the --with-http_realip_module option to enable it during compilation. realip scope set_real_ip_from, real_ip_header and real_ip_recursive can all be used in http, server and location zone configurations. Explanation of some realip parameters
Explanation of X-Forwarded-For, X-Real-IP, and Remote Address in the http header X-Forwarded-For is located in the HTTP request header and is an extended header of HTTP, used to indicate the real IP address of the HTTP request end. The format is as follows: X-Forwarded-For: client, proxy1, proxy2 Nginx proxy is generally configured as: proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; explain:
Realip function example Here is a simple architecture diagram: Assumption 1: 1. If Nginx does not use the realip module, the X-Forwarded-For request in the second Nginx is 1.1.1.1, but the remote_addr address is 2.2.2.2. At this time, the application service can obtain the user's real IP through the X-Forwarded-For field. However, there is a risk here. If there are multiple layers of reverse proxy services in the middle, it will be impossible to obtain the unique user's real IP. 2. If Nginx uses the realip module and is configured as follows, Nginx will take the last IP in X-Forwarded-For, which is 2.2.2.2, as the real IP. Finally, the address obtained by the application service is also 2.2.2.2, but in fact this is not the user's IP. set_real_ip_from 2.2.2.2; set_real_ip_from 2.2.2.3; real_ip_header X-Forwarded-For; real_ip_recursive off; 3. If Nginx uses the realip module and is set up as follows; since 2.2.2.2 is a trusted server IP, Nginx will continue to search forward and find that 1.1.1.1 is not a trusted server IP, it will consider it to be the real IP. But the fact is that 1.1.1.1 is the user's IP. Finally, the application service also obtains the unique real IP of the user. set_real_ip_from 2.2.2.2; set_real_ip_from 2.2.2.3; real_ip_header X-Forwarded-For; real_ip_recursive on; Summarize This is the end of this article about the use of realip module in Nginx basic learning. For more information about the use of Nginx realip module, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: JavaScript function call, apply and bind method case study
>>: The difference between key and index in MySQL
Table of contents Target Thought Analysis Code la...
MYSQL is case sensitive Seeing the words is belie...
Border Style The border-style property specifies ...
Navigation and other things are often used in dai...
This article shares the specific code of jquery+A...
In MySQL, we often use order by for sorting and l...
Sometimes we may need to operate servers in batch...
# Adjust VMware hard disk boot priority Step 1: E...
Since I installed the official version of IE8.0, ...
The most understandable explanation of the accura...
1. Download and install Download the community ed...
We often see a cool effect where the mouse hovers...
Recently, I have done a simple study on the data ...
Table of contents 1. Check the current status of ...
Table of contents 1. Introduction 2. Use 1. Diffe...