Nginx and Apache logs record users' real IP addresses: X-real-IP

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.