简体   繁体   中英

How to retrieve port number from a tomcat server sitting behind a load-balancer

Situation:

  • My client has a Java web application deployed on a JBoss server, it is accessed both via HTTPS and HTTP
  • The JBoss server is sitting behind a load-balancer that handles the SSL, in other words this load-balancer terminates SSL and sends requests to JBoss as plain HTTP

Problem I need to solve:

The web application deployed on JBoss needs to know what port the load-balancer is using for HTTPS , so that it can direct users to certain HTTPS urls correctly. This cannot be hard-coded because the application will be deployed on multiple clients, each of them have different configurations for the load-balancer.

My approach (which didn't work) :

I am defining the port from a jspx page, via ${pageContext.request.serverPort} , but this always returns the port for HTTP because JBoss always gets the request via HTTP.

Thanks in advance. I've looked at this question but was not helpful.

There isn't really a way to determine the port if tomcat is sitting behind a load balancer. As suggested in the comments, exposing the port configuration to your clients would be the best for now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM