In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
1. Environment deployment instructions
The back end is deployed on the tomcat server, and the front end uses nginx for proxy access
Tomcat deployment directory
Nginx configuration:
Upstream wcfront {server localhost:8991;// background interface} server {listen 8998 / Universe h6 access interface server_name 192.168.2.37; charset utf-8; proxy_set_header Host $host:$server_port; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; location ^ ~ / fs/ {alias / var/zkbc/fs/ } location = / {root / opt/nlcn/backend/wcfront/www;//h6 page path index index.html index.htm;} location = / index {root / opt/nlcn/backend/wcfront/www; rewrite ^ (. *) /;} location ~. *\. (html) ${root / opt/nlcn/backend/wcfront/www; index index.html index.htm } location ~. * (css) ${root / opt/nlcn/backend/wcfront/www; index index.html index.htm;} location ~. *\. (html | htm | gif | jpeg | bmp | png | ico | txt | js | css | woff | woff2 | svg | ttf) ${root / opt/nlcn/backend/wcfront/www; index index.html index.htm;} location / {proxy_pass http://wcfront; proxy_set_header Host $host:$server_port;}}
2. The ip obtained by the backend of the current configuration has not been 127.0.0.1. Now the requirement is to be able to obtain the ip of the client.
(1) add the following configuration to the nginx configuration. Note: add it under location /.
Location / {proxy_pass http://wcfront; proxy_set_header Host $host:$server_port; proxy_set_header Remote_Addr $remote_addr; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;}
(2) restart nginx
Nginx-s reload
Ps-ef | grep nginx can check the startup status and startup time of nginx
(3) configure tomcat
Found pattern= "h l u t" r "s b" / > under service.xml
Modify% h to% {X-Real-IP} I
Restart the service
(4) how to obtain client ip by java
Public static String getIpAddress (HttpServletRequest request) {String ip = null; / / X-Forwarded-For:Squid Service Agent String ipAddresses = request.getHeader ("X-Forwarded-For"); if (ipAddresses = = null | | ipAddresses.length () = = 0 | | "unknown" .equalsIgnoreCase (ipAddresses)) {/ / Proxy-Client-IP:apache Service Agent ipAddresses = request.getHeader ("Proxy-Client-IP") } if (ipAddresses = = null | | ipAddresses.length () = = 0 | | "unknown" .equalsIgnoreCase (ipAddresses)) {/ / WL-Proxy-Client-IP:weblogic service proxy ipAddresses = request.getHeader ("WL-Proxy-Client-IP") } if (ipAddresses = = null | | ipAddresses.length () = = 0 | | "unknown" .equalsIgnoreCase (ipAddresses)) {/ / HTTP_CLIENT_IP: some proxy servers ipAddresses = request.getHeader ("HTTP_CLIENT_IP") } if (ipAddresses = = null | | ipAddresses.length () = = 0 | | "unknown" .equalsIgnoreCase (ipAddresses)) {/ / X-Real-IP:nginx service proxy ipAddresses = request.getHeader ("X-Real-IP") } / / if some networks use multi-layer proxies, multiple ip will be obtained, usually separated by a comma (,), and the first ip is the real IP if of the client (ipAddresses! = null & & ipAddresses.length ()! = 0) {ip = ipAddresses.split (",") [0] } / / still can not be obtained, finally through request.getRemoteAddr (); get if (ip = = null | | ip.length () = = 0 | | "unknown" .equalsIgnoreCase (ipAddresses)) {ip = request.getRemoteAddr ();} return ip;}
3. Conclusion
It is important to note that this method obtains the extranet address of the network where the client is located, not the real ip of the client.
For example
Multiple terminals are accessed in the same local area network, and the ip obtained is the same gateway address.
For 4G mobile phone access, the ip obtained is not the actual ip of the mobile phone, but the network ip. For example, the obtained ip is 61.158.147.109, but the actual mobile phone ip is 61.158.147.* (another ip address of the same network segment). It is not particularly clear about the relationship between mobile ip and 109. interested friends can study it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.