Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

481
Views
Obtain the client's IP in Nextjs

I need the client's IP in Next. But unfortunately, all the methods I searched for, gave me the IP of the server and the local IP of the server. As far as I know, the requests from the client first go to the server and after passing Nginx, it is redirected to the site, where the IP is obtained, which is the IP of the server. Here are all the methods I have used so far.

//in _app.js file
1)appContext?.ctx?.req?.headers["x-forwarded-for"] || "")
      .split(",")
      .pop()
      .trim() || 2)appContext?.ctx?.req?.connection?.remoteAddress;

3)appContext?.ctx?.req?.socket?.remoteAddress;

4)requestIp.getClientIp(appContext?.ctx?.req);

5)let ip =
    appContext?.ctx?.req?.headers["x-real-ip"] ||
    appContext?.ctx?.req?.connection.remoteAddress;
  if (ip.substr(0, 7) == "::ffff:") {
    ip = ip.substr(7);
  }
  
6)appContext?.ctx?.req?.headers["x-userip"];

7)appContext?.ctx?.req?.clientIp

8)const forwarded = appContext?.ctx?.req?.headers["x-forwarded-for"];
  const ip = forwarded
    ? forwarded.split(/, /)[0]
    : appContext?.ctx?.req?.connection?.remoteAddress;
//in server.js file
9)server.set("trust proxy", false);

10)server.set("trust proxy", true);

import requestIp from "request-ip";
11)server.use(requestIp.mw());

12)server.use(function (req, res, next) {
    if (req.method === "get") {
      var ip = req.headers["x-real-ip"] || req.connection.remoteAddress;
      if (ip.substr(0, 7) == "::ffff:") {
        ip = ip.substr(7);
        console.log("ippppppppp", ip);
      }
    }
    next();
  });
  
13)server.use(function (req, res) {
    const ip = req.clientIp;
    res.end(ip);
  });
  

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!