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.