Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Nginx acts as a reverse proxy, and the back-end tomcat server obtains the real client IP.

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

If you want to record the real client access address, you need to configure it as follows:

1. Reverse proxy server nginx.conf configuration

Add three parameters after server to record IP:

Proxy_set_header Host $host

Proxy_set_header X-Real-IP $remote_addr

Proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for

Case study:

Server {

Listen 80

Server_name 10.10.32.29

Upstream tomcat {ip_hash; server 10.10.32.29:8080 max_fails=1 fail_timeout=10s weight=1; server 10.10.32.30:8080 max_fails=1 fail_timeout=10s weight=1;} location / {

Proxy_pass http://tomcat;

Proxy_redirect default

Proxy_set_header Host $host

Proxy_set_header X-Real-IP $remote_addr; # Real client ip before retaining the proxy

Proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # record the agent process

}

Error_page 500 502 503 504 / 50x.html

Location = / 50x.html {

Root html

}

}

2. Modify the configuration file of tomcat

Modify in server.xml

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report