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 Problem Description Solution Pr...
I saw that Taobao’s webpage uses import, while man...
<br />Original link: http://www.dudo.org/art...
Ping www.baidu.com unknown domain name Modify the...
About Event: MySQL 5.1 began to introduce the con...
1. In the control panel, uninstall all components...
The execution relationship between the href jump ...
This article is based on the Windows 10 system en...
General CSS code will only cause minor issues wit...
1. What is it? MySQL is the most popular relation...
What is a sticky footer layout? Our common web pa...
Copy data When copying data remotely, we usually ...
Preface I watched web.dev's 2020 three-day li...
For example: Copy code The code is as follows: <...
Table of contents 1. Structural instructions Modu...