Nginx+tomcat to obtain remote User IP problem Resolution

Source: Internet
Author: User
nginx+ (1...N) when a tomcat cluster is deployed, back-end Tomcat needs to acquire the user's IP, which is always achieved through REQUEST.GETREMOTEADDR () 127.0.0.1.

Because the user requests after NGINX,NGIGX forwarded the request to Tomcat, Tomcat obtains always the Nginx IP, if needs to obtain the real user IP, only need to make some configuration on the Ngix.

Location/Down settings
Proxy_set_header X-real-ip $remote _addr;
Proxy_set_header Host $host;

Test configuration:./sbin/nginx-t-C conf/nginx.conf correct after restarting Nginx.

The Java code is modified as follows

Out.println ("X-real-ip:" + request.getheader ("X-real-ip") + "
");

Where X-real-ip is the user's real IP

Note: X-REAL-IP is a variable, you can change the name according to your own needs.

The above describes the Nginx+tomcat to obtain the remote User IP problem resolution, including the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.