Tomcat gets the real user IP of Nginx

Source: Internet
Author: User
Required: Add proxy_set_header x-real-ip $remote _addr;

Upstream Tomcat_server {server localhost:8080 weight=1;        } server {Listen 80;        server_name 192.168.40.116;        #charset Koi8-r; #access_log logs/host.access.log main;location ~* "\.       (jsp|do) $ "{#当请求的是jsp或do文件时直接到tomcat上去取 #root html;         #index index.html index.htm;          #proxy_pass http://192.168.18.201/;       Proxy_pass http://tomcat_server;client_max_body_size 2048m;       Client_body_buffer_size 128k;       Proxy_connect_timeout 600;       Proxy_read_timeout 600;       Proxy_send_timeout 6000;       Proxy_buffer_size 16k;       Proxy_buffers 64k;       Proxy_busy_buffers_size 64k;        Proxy_temp_file_write_size 64k; } location/{#发布目录/data/www # root/home/ding/itsoftware/tomcat/webapps/100mshcloud;# FA Stcgi_pass 192.168.40.116:8080;proxy_set_header x-real-ip $remote _addr; Proxy_pass http://tomcat_server/;        #注释默认两行, add a row.        # index index.html index.htm; }

Tomcat gets:

public static String Getremoteaddrip (HttpServletRequest request) {      string ipfromnginx = GetHeader (Request, " X-real-ip ");      System.out.println ("Ipfromnginx:" + Ipfromnginx);      System.out.println ("getremoteaddr:" + request.getremoteaddr ());      Return Stringutil.isempty (Ipfromnginx)? REQUEST.GETREMOTEADDR (): Ipfromnginx;  }      private static string GetHeader (HttpServletRequest request, String headname) {      String value = Request.getheader ( Headname);      Return! Stringutils.isblank (value) &&! " Unknown ". Equalsignorecase (value)? Value: "";  }  

The above describes the tomcat to get nginx real User IP, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Related Article

    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.