If there is a reverse proxy in the structure, the log records on the backend machine will be the proxy IP address, and the real IP address cannot be seen, the backend code can be solved by setting the real IP address in the header. Add the following section to nginx:
Proxy_set_header X-real-IP $ remote_addr;
The backend is obtained through the X-REAL-IP or the http_x_real_ip variable.
For logging, nginx can define the $ http_x_real_ip variable, for example:
Log_format main '$ http_x_real_ip-$ remote_user'
'[$ Time_local] "$ request_method $ scheme: // $ host $ request_uri $ server_protocol "'
'$ Status $ body_bytes_sent "$ http_referer "'
'"$ Http_user_agent" "$ http_x_forwarded_for"-$ remote_addr ';
Apache can be obtained through % {X-real-IP} I:
Logformat "% {X-real-IP} I % L % u % t \" % m http: // % v % u % Q \ "%> S % B \" % {Referer} I \ "\" % {User-Agent} I \ "-% H" combinedall
This article is from the Nick blog, please be sure to keep this source http://8177627.blog.51cto.com/8167627/1431056