Using ServletUriComponentsBuilder with Nginx

Spring’s ServletUriComponentsBuilder.fromCurrentRequest() can be really convinient to build an URL from the current request. However, when using Nginx, things might work so well.

The solution is simple, just add these headers to your Nginx configuration file:

proxy_set_header        X-Forwarded-Host   $host:443;
proxy_set_header        X-Forwarded-Server $host;
proxy_set_header        X-Forwarded-Port   443;
proxy_set_header        X-Forwarded-Proto  https;
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s