|
Nginx Module Development - get user ip
Core code:
if (r-> headers_in.x_real_ip! = NULL) {
ngx_log_error (NGX_LOG_ERR, r-> connection-> log, 0, "% V", & r-> headers_in.x_real_ip-> value);
} Else {
sockaddr_in * sin = (sockaddr_in *) (r-> connection-> sockaddr);
ngx_log_error (NGX_LOG_ERR, r-> connection-> log, 0, "% s", inet_ntoa (sin-> sin_addr));
}
Code testing so that
Code means: If Header has x-real-ip, it is treated as ip, ip otherwise get from the socket, there simply will be printed to the error log ip Lane
Where r is ngx_http_request_t pointer know nginx module to develop basic data structures will know this, if you do not know, please do understand separately
Tucao: I spent a morning time looking nginx module How to obtain ip, seemingly not much information on the Internet, just google a buddy said to go in the socket connection to get, a ready-made package nginx could not function? |
|
|
|