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

Tomcat gets the client domain name of the Nginx reverse proxy

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

problem

After Nginx reverse proxy, the Tomcat application gets the host of Nginx through request.getHeader ("host"), which is not the real domain name on the address bar of the client browser.

For example, on a server, the port number of Tomcat is 8080 and the port number of Nginx is port 8080.

Server {listen 80; location / {proxy_pass http://127.0.0.1:8080;}}

Open http:///test on another machine to access the application under Tomcat and get the client domain name.

System.out.println (request.getHeader ("host"))

The result is:

Localhost:8080

The cause of the problem

The reverse proxy of Nginx is actually a bridge between the client and the real application server. The client (usually the browser) accesses the Nginx server, and the Nginx accesses the Web application server. For Web applications, the client of this HTTP request is Nginx rather than the real client browser. If there is no special treatment, Web applications will treat Nginx as the client of the request, and the client information obtained is some information of Nginx.

Problem solving

Nginx configures HTTP Header. Host contains the real domain name and port number of the client

Proxy_set_header Host $http_host

Tomcat gets the client information from the HTTP Header passed by Nginx.

Summary

The above is the whole content of this article. I hope the content of this article has a certain reference and learning value for everyone's study or work. Thank you for your support. If you want to know more about it, please see the relevant links below.

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