nginx stream_realip_module
时间: 2023-09-07 07:15:02 浏览: 49
The nginx stream_realip_module is a module that allows nginx to obtain the real IP address of a client by replacing the client's IP address with the one specified in the X-Forwarded-For or X-Real-IP header. This is useful in situations where nginx is behind a load balancer or proxy server, as the original client IP address may be lost in the process.
When the stream_realip_module is enabled, nginx replaces the client's IP address with the IP address specified in the X-Forwarded-For or X-Real-IP header. This allows the actual client IP address to be logged and used for access control, rate limiting, or other purposes.
To use the stream_realip_module, the following steps are required:
1. Install nginx with the stream_realip_module enabled.
2. Add the following configuration to the nginx.conf file:
```
stream {
real_ip_header X-Forwarded-For;
real_ip_recursive on;
...
}
```
In this example, the real IP address is obtained from the X-Forwarded-For header and the `real_ip_recursive` option is enabled to allow multiple X-Forwarded-For headers to be processed.
3. Restart nginx.
Once the stream_realip_module is configured, nginx will obtain the real IP address of the client and use it in place of the proxy or load balancer IP address. This can help ensure that access control and other security measures are applied correctly.