How to get server details from HttpServletRequest

I did the change to the nginx on that machine. So I’d expect the following to work now:

String host =  request.getHeader(HttpHeaders.HOST);
	
String scheme = request.getHeader(HttpHeaders.X_FORWARDED_PROTO);
if (scheme == null) {
    scheme = request.getScheme();
}

I think ‘X-Forwarded-Host’ is not what you are looking for.

The above request sets the "Host" header to the $host variable, which should contain information about the original host being requested. The X-Forwarded-Proto header gives the proxied server information about the schema of the original client request (whether it was an http or an https request).

The X-Real-IP is set to the IP address of the client so that the proxy can correctly make decisions or log based on this information. The X-Forwarded-For header is a list containing the IP addresses of every server the client has been proxied through up to this point. In the example above, we set this to the $proxy_add_x_forwarded_for variable. This variable takes the value of the original X-Forwarded-For header retrieved from the client and adds the Nginx server's IP address to the end.
1 Like