Nginx Reverse proxy tomcat logs get real IP

Source: Internet
Author: User
Tags nginx reverse proxy

Today test the Nginx reverse proxy function, let the Tomcat log to get the user real IP address, Google a bit, is an article content, copied the tomcat configuration file to modify the content, how can not get, magical! Helpless under, carefully read the copy of each line of content, found that the problem, it is estimated that if the search for the article, it is impossible to obtain the real IP address, a small place. To start checking configuration content:

(1) Nigix nginx.conf configuration file:

proxy_set_header  Host $host; proxy_set_header  X-Real-IP $remote_addr; proxy_set_header  X-Forwarded-For   $proxy_add_x_forwarded_for;

# # # Confirm no errors, but note:x-real-IP (small red bars)

(2) in the Tomcat server.xml configuration file:

<valve classname= "Org.apache.catalina.valves.AccessLogValve"

directory= "Logs" prefix= "Tomcat_access_log." suffix= ". txt"

pattern= "%a%r%t%{x-real_ip}i" resolvehosts= "false"/>

# # # Attention, attention, see the problem? %{x-real_ip}i not x-real-IP, Universal copy Ah, Bo master How to write the underline, find the problem modified, restart Tomcat, the client real IP address into the log. Oh, who want to copy the content of the article to ensure that no one will be to haha!

This article is from the "Old Wafangdian" blog, please be sure to keep this source http://laowafang.blog.51cto.com/251518/1684104

Nginx Reverse proxy tomcat logs get real IP

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.