Forwarding cliend ip to separated backend on app router
Unanswered
Satin posted this in #help-forum
SatinOP
Hi everyone! đź‘‹
I’m working on a Next.js (v14) App Router and API Routes for fetch using project where I need to forward the client’s IP address (e.g., from X-Forwarded-For or X-Client-Ip) to a separated backend API.
I’ve tried some hardcoded methods, but when checking tools like New Relic, I’m not seeing the client IP being logged on the backend. Instead, I only see the IP of the Next.js server or proxy.
Does anyone know the best way to:
Extract the client’s real IP in the Next.js middleware or App Router?
Forward this IP to my backend as part of the request headers (e.g., X-Client-Ip)?
Any tips or examples would be greatly appreciated! 🙏
I’m working on a Next.js (v14) App Router and API Routes for fetch using project where I need to forward the client’s IP address (e.g., from X-Forwarded-For or X-Client-Ip) to a separated backend API.
I’ve tried some hardcoded methods, but when checking tools like New Relic, I’m not seeing the client IP being logged on the backend. Instead, I only see the IP of the Next.js server or proxy.
Does anyone know the best way to:
Extract the client’s real IP in the Next.js middleware or App Router?
Forward this IP to my backend as part of the request headers (e.g., X-Client-Ip)?
Any tips or examples would be greatly appreciated! 🙏
6 Replies
You've to configure through NGINX, to forward ip
@"use php" You've to configure through NGINX, to forward ip
SatinOP
oh i see i will check this out, if you have recommendation about configuration as guide or docs smt i would be glad.
also do you think i need to do smt more on frontend. Unfortunately we are using api routes on app directory so i just update my util that is using on request handler to add the ip as x-forwarded-for to request header.
also do you think i need to do smt more on frontend. Unfortunately we are using api routes on app directory so i just update my util that is using on request handler to add the ip as x-forwarded-for to request header.
for getting IP, I don't think any change on frontend is required.
SatinOP
okay i will consider your tip
thanks
@"use php" You've to configure through NGINX, to forward ip
Mark solution please @Satin