How can I configure the x-forwarded-for header in nginx?

I need to store user’s real ip addresses. I can debug a few properties from the request headers like below.

accept: 'application/json, text/plain, */*',

2022-12-30T06:51:22.286 app[1e9759f6] nrt [info] 'user-agent': 'axios/1.1.3',

2022-12-30T06:51:22.286 app[1e9759f6] nrt [info] 'accept-encoding': 'gzip, deflate, br',

2022-12-30T06:51:22.286 app[1e9759f6] nrt [info] 'x-request-start': 't=1672383082282366',

2022-12-30T06:51:22.286 app[1e9759f6] nrt [info] 'fly-client-ip': '3.38.145.5',

2022-12-30T06:51:22.286 app[1e9759f6] nrt [info] 'x-forwarded-for': '3.38.145.5, 137.66.22.161',

2022-12-30T06:51:22.286 app[1e9759f6] nrt [info] 'fly-forwarded-proto': 'https',

2022-12-30T06:51:22.286 app[1e9759f6] nrt [info] 'x-forwarded-proto': 'https',

2022-12-30T06:51:22.286 app[1e9759f6] nrt [info] 'fly-forwarded-ssl': 'on',

2022-12-30T06:51:22.286 app[1e9759f6] nrt [info] 'x-forwarded-ssl': 'on',

2022-12-30T06:51:22.286 app[1e9759f6] nrt [info] 'fly-forwarded-port': '443',

2022-12-30T06:51:22.286 app[1e9759f6] nrt [info] 'x-forwarded-port': '443',

The problem is, the value inside x-forwarded-for header is always the same and it does not changed neither when I test on my mobile(LTE) nor on my pc(Ethernet). The ip address seems like a local address of Amazon server or maybe the client-side load balancer’s ip. I’m not sure. My client side app is hosted on Vercel.

How can I store a real ip address from the incoming request?

I’m not familiar with Vercel, but is it possible that your client-side app is making queries from the Vercel server? Looking at the fly-client-ip header, it does show an Amazon AWS IP, so that’s where Fly is getting a connection from.

Thanks for the response @lillian
Yes, my client-side app is making queries from the Vercel server and it is the Nextjs app. I want the actual user’s public ip, not the AWS Lamda instance ip. Any ideas?

In that case, you’d need to either make the request from the web browser (so it’s sent from the user’s IP), or manually read the user’s IP in NextJS and add it to the query.

@lillian I’ve already done using 3rd party ip lookup service to fetch the user’s ip address.
Then I included the address in the request header, but it still didn’t work. Am I missing something?

Sorry, I don’t know enough about your app to help you further. The docs of AWS Lambda, or Vercel, should tell you how to get the user’s IP address from the request; I don’t think a 3rd party IP address lookup service is useful here

Thanks man. The problem resolved :slight_smile: