Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

493
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda