# Using ServletUriComponentsBuilder with Nginx

Author: [Wim Deblauwe](https://www.wimdeblauwe.com/about/) | Published: 2017-03-13 | Canonical: https://www.wimdeblauwe.com/blog/2017/2017-03-13-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;
```

_UPDATE 2020-06-08_

You need to enable support for this in Spring Boot by setting the following property (Since Spring Boot 2.2):

```
server.forward-headers-strategy=native
```

