Originally published on ClarioStudio. Written with AI assistance and checked against primary sources by the ClarioStudio team before publishing.

If nginx sits in front of your Spring Boot app, your app only knows what nginx tells it. With a bare proxy_pass, that is almost nothing. In our test the app saw every request coming from 127.0.0.1, over plain http, for host 127.0.0.1:8080.

This week's nginx 1.30.7 security release has a lot of teams opening their proxy config. While you have it open, it takes about ten minutes to check what your app actually receives. We set up nginx and a tiny Java backend that prints its request headers, then tried five configs. The one that surprised us was a single extra line in a location block that silently dropped every forwarded header for that path.

In short

  • Without proxy_set_header lines, nginx sends no client IP and no scheme, and replaces the Host header with the upstream address.
  • A proxy_set_header inside a location cancels all the ones set at server level for that location. Grep for it.
  • Spring Boot ignores forwarded headers until you set server.forward-headers-strategy, and it should only be on when nothing but nginx can reach port 8080.

Do you need to check?

You need this check if nginx terminates TLS (handles HTTPS and talks plain HTTP to your app) or picks the backend, and your app uses the client IP, the scheme or the host.

Your app does this What breaks without forwarded headers
Spring Security redirects to /login, OAuth2 login, absolute URLs in emails Links built as http:// or with the internal host
Rate limiting, audit logs, IP allowlists Every client looks like the proxy
Reads X-Forwarded-For by hand in a filter or controller Depends on how nginx builds the header (see Step 3)
Only relative links, never looks at client IP Little or nothing

The "you already patched nginx" check is in our NGINX2Root post. This guide is about what happens after the proxy hands the request on.

Step 1: See what a bare proxy_pass sends

A proxy_pass with no headers set tells the backend nothing about the client. We ran everything on Ubuntu 24.04 with nginx 1.24.0 (Ubuntu package 1.24.0-2ubuntu7.20) and OpenJDK 21.0.13, all on one machine. We added the documentation address 203.0.113.7 to the loopback interface and sent requests to it, so nginx saw 203.0.113.7 as the client.

The backend is one Java file using the JDK's built-in HTTP server, so it needs no Spring or Maven. It plays the part of your app on port 8080 and prints what it receives:

import com.sun.net.httpserver.HttpServer; import java.net.InetSocketAddress; import java.nio.charset.StandardCharsets; // Prints what a backend on port 8080 receives from nginx. public class HeaderEcho { public static void main(String[] args) throws Exception { String bind = args.length > 0 ? args[0] : "127.0.0.1"; HttpServer server = HttpServer.create(new InetSocketAddress(bind, 8080), 0); server.createContext("/", exchange -> { var h = exchange.getRequestHeaders(); String body = "remoteAddr=" + exchange.getRemoteAddress().getAddress().getHostAddress() + "\n" + "Host=" + h.getFirst("Host") + "\n" + "X-Forwarded-For=" + h.getFirst("X-Forwarded-For") + "\n" + "X-Forwarded-Proto=" + h.getFirst("X-Forwarded-Proto") + "\n" + "X-Forwarded-Host=" + h.getFirst("X-Forwarded-Host") + "\n"; byte[] out = body.getBytes(StandardCharsets.UTF_8); exchange.sendResponseHeaders(200, out.length); exchange.getResponseBody().write(out); exchange.close(); }); server.start(); System.out.println("listening on " + bind + ":8080"); } } 

Start it with java HeaderEcho.java on a test machine, not on production. Our first nginx server block was the minimum:

server { listen 8081; location / { proxy_pass http://127.0.0.1:8080; } } 

To send test requests, including ones with a header the client made up, we used a second small Java file instead of a browser:

import java.io.*; import java.net.*; import java.nio.charset.StandardCharsets; // Usage: java Probe.java <host> <port> [path] [X-Forwarded-For value to send] // Sends one HTTP/1.1 GET (TLS when the port is 8443) and prints the body. public class Probe { public static void main(String[] a) throws Exception { String host = a[0], path = a.length > 2 ? a[2] : "/"; int port = Integer.parseInt(a[1]); String forged = a.length > 3 ? "X-Forwarded-For: " + a[3] + "\r\n" : ""; try (Socket s = port == 8443 ? javax.net.ssl.SSLSocketFactory.getDefault().createSocket(host, port) : new Socket(host, port)) { String req = "GET " + path + " HTTP/1.1\r\nHost: app.example.com\r\n" + forged + "Connection: close\r\n\r\n"; s.getOutputStream().write(req.getBytes(StandardCharsets.US_ASCII)); String resp = new String(s.getInputStream().readAllBytes(), StandardCharsets.UTF_8); System.out.print(resp.substring(resp.indexOf("\r\n\r\n") + 4)); } } } 

java Probe.java 203.0.113.7 8081 sends a request with Host: app.example.com to that server block. The backend printed:

remoteAddr=127.0.0.1 Host=127.0.0.1:8080 X-Forwarded-For=null X-Forwarded-Proto=null X-Forwarded-Host=null 

The client address, the scheme and the original host are all gone. nginx even rewrote the Host header to the upstream address. A Spring app here would build redirects to http://127.0.0.1:8080/login.

Step 2: Set the headers, and check the result

Four proxy_set_header lines give the backend the client IP, scheme and host. This is the server block we used for the next test:

server { listen 8082; location / { proxy_pass http://127.0.0.1:8080; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Host $host; } } 

Same request, new output:

remoteAddr=127.0.0.1 Host=app.example.com X-Forwarded-For=203.0.113.7 X-Forwarded-Proto=http X-Forwarded-Host=app.example.com 

remoteAddr is still the proxy, as it should be. The client IP now travels in the header. We then put the same headers in a server block with listen 8443 ssl;, ssl_certificate and ssl_certificate_key pointing at a self-signed test certificate. There X-Forwarded-Proto came through as https. That one header is what tells your app to build https:// links.

Step 3: Decide whether to append to X-Forwarded-For

$proxy_add_x_forwarded_for keeps whatever the client sent and adds the real address at the end. Many example configs use it. We sent a request that already carried a made-up X-Forwarded-For: 10.0.0.5 through both styles:

nginx line Backend received
X-Forwarded-For $remote_addr 203.0.113.7
X-Forwarded-For $proxy_add_x_forwarded_for 10.0.0.5, 203.0.113.7

The appended form is right when another proxy or load balancer sits in front of nginx and you need its entries. It is a problem for any code that takes the first value. A filter that does header.split(",")[0] would log this client as 10.0.0.5, a private address it chose.

Tomcat, the web server inside Spring Boot by default, reads the list the other way. Its RemoteIpValve, the component that applies forwarded headers, is described in the Tomcat 10.0 API docs. It reads the values right to left and skips the ones that match internal proxies. It stops at the first address that is neither internal nor trusted. So for the second row, Tomcat would settle on 203.0.113.7. Hand-written code usually does not.

If nginx is the first thing clients reach, $remote_addr is the simpler choice. If you keep the appended form, let Tomcat pick the client IP rather than parsing the header yourself.

Step 4: Find the location block that drops your headers

A proxy_set_header in a location replaces every proxy_set_header from the server level for that location. We hit this with a config that looks harmless:

server { listen 8084; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-Forwarded-Proto $scheme; location / { proxy_pass http://127.0.0.1:8080; } location /api/ { proxy_pass http://127.0.0.1:8080; proxy_set_header X-Request-Id $request_id; } } 

Requests to / arrived with all three headers. Requests to /api/x arrived like Step 1:

remoteAddr=127.0.0.1 Host=127.0.0.1:8080 X-Forwarded-For=null X-Forwarded-Proto=null X-Forwarded-Host=null 

We expected /api/ to get four headers. It got none of ours. Adding the request ID header removed the inherited ones. The fix is to repeat the full set inside that location, or move all of them into a shared file and include it in every location that proxies.

To find these blocks on your own server, print the running config and look at where each header is set (run as root):

nginx -T 2>/dev/null | grep -nE '^\s*(server|location|proxy_pass|proxy_set_header)\b' 

nginx -T prints the whole running config, with every include file pasted in, so the line numbers count from the top of that output, not from your site file. On the config above it printed:

190:server { 192: proxy_set_header Host $host; 193: proxy_set_header X-Forwarded-For $remote_addr; 194: proxy_set_header X-Forwarded-Proto $scheme; 196: location / { 197: proxy_pass http://127.0.0.1:8080; 199: location /api/ { 200: proxy_pass http://127.0.0.1:8080; 201: proxy_set_header X-Request-Id $request_id; 

Any location that has a proxy_pass and at least one proxy_set_header, but not the forwarded ones, is a block to fix.

Step 5: Tell Spring Boot to use the headers

Spring Boot ignores forwarded headers by default. The Spring Boot 4.1 how-to says server.forward-headers-strategy defaults to NONE unless the app runs on a supported cloud platform, where it defaults to NATIVE. Its documented values are NATIVE, which lets the embedded web server handle the headers itself, and FRAMEWORK, which uses Spring's own filter.

For the embedded Tomcat behind nginx, the documented setting is one line in application.properties:

server.forward-headers-strategy=native 

We could not run a Spring Boot app in our environment, so this block is from the docs, not from our test. With it, Tomcat applies the RemoteIpValve. Per the Tomcat docs above, that sets the request's remote address from X-Forwarded-For, and turns the scheme to https and the port to 443 when X-Forwarded-Proto says https. The same Spring page adds that when TLS ends at the proxy, you should also set server.tomcat.redirect-context-root=false.

If your proxy uses other header names, the docs show server.tomcat.remoteip.remote-ip-header and server.tomcat.remoteip.protocol-header for renaming them.

Step 6: Make sure only nginx can reach port 8080

Forwarded headers are only trustworthy if clients cannot talk to your app directly. Spring's cloud deployment guide puts it plainly: turn this on only when traffic comes from a trusted proxy and the app is reachable only from a trusted network.

Check what address the app listens on:

ss -ltn | grep ':8080' 

We started the echo backend twice, once with java HeaderEcho.java (loopback) and once with java HeaderEcho.java 0.0.0.0 (all addresses):

LISTEN 0 50 127.0.0.1:8080 0.0.0.0:* LISTEN 0 50 0.0.0.0:8080 0.0.0.0:* 

On the 0.0.0.0 one, we skipped nginx and sent the made-up header straight to port 8080 (java Probe.java 203.0.113.7 8080 / 10.0.0.5). It arrived untouched:

remoteAddr=203.0.113.7 Host=app.example.com X-Forwarded-For=10.0.0.5 X-Forwarded-Proto=null X-Forwarded-Host=null 

Tomcat only applies the forwarded headers when the direct caller matches its internal or trusted proxy lists. The Tomcat 11 Remote IP Valve docs give its own default for internal proxies as all private ranges and loopback (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, 127.0.0.0/8 and others). Spring Boot sets this through server.tomcat.remoteip.internal-proxies; the how-to shows narrowing it to 192\.168\.\d{1,3}\.\d{1,3} and warns never to set it empty in production. Its exact default lives in the Boot properties appendix, which we could not open.

In practice, a stranger on the internet is not a trusted proxy, but another container or VM on your private network is. If anything besides nginx shares that network, make the app listen on 127.0.0.1 only (as our first echo backend did) or firewall port 8080, and narrow internal-proxies to your nginx address. If nginx runs in its own container, loopback is not an option; limit port 8080 to the nginx container with your firewall or network rules instead.

Traps we saw or the docs warn about

Trap What happens Fix
proxy_set_header added in one location That path loses all inherited forwarded headers Repeat the set or include a shared file
No Host $host App sees 127.0.0.1:8080 as its host Set Host $host
Code takes the first X-Forwarded-For value Client can choose its logged IP Use $remote_addr, or let Tomcat resolve it
Port 8080 open to the private network Any host there can send forwarded headers Tomcat trusts Bind to loopback, firewall, narrow internal-proxies

What we didn't test

  • A running Spring Boot app. Maven Central was unreachable from our machine, so the application.properties lines in Step 5 come from the Spring Boot docs. We did not see Tomcat's RemoteIpValve change a request ourselves.
  • Spring's FRAMEWORK mode and its filter. We could not open the Spring Framework page that covers it.
  • The default value of server.tomcat.remoteip.internal-proxies in Spring Boot 4.1. We read Tomcat's own default, not Boot's.
  • The Forwarded header (RFC 7239), HTTP/2 to the backend, and nginx versions other than 1.24.0.

Do this today

Run the nginx -T grep from Step 4 on your production proxy, and fix any location that sets one header but not the forwarded ones. Then check ss -ltn on the app host before you turn on server.forward-headers-strategy=native. If you would rather see the effect first, put the HeaderEcho class on a staging box behind a copy of your nginx config.

How we made this
Sources checked on November 20, 2026. We ran nginx 1.24.0 (Ubuntu 24.04 package) and the HeaderEcho backend on OpenJDK 21.0.13, and sent test requests with a short Java client, including over a TLS listener with a self-signed certificate. We did not run Spring Boot or Tomcat; those steps rely on their documentation.
Drafted with AI tools, fact-checked against the sources and edited by the ClarioStudio desk.

Related reading

Sources

  1. Spring Boot 4.1.2, Embedded Web Servers how-to: Running Behind a Front-end Proxy Server. Checked November 20, 2026.
  2. Spring Boot 4.1.2, Deploying to the Cloud. Checked November 20, 2026.
  3. Apache Tomcat 11, The Valve Component: Remote IP Valve. Checked November 20, 2026.
  4. Apache Tomcat 10.0, RemoteIpValve API documentation. Checked November 20, 2026.
  5. nginx.org, nginx news (1.30.7 and 1.31.9, November 18, 2026). Checked November 20, 2026.