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

171
Views
Unable to print the IP of a request on an expressjs server behind nginx?

I tried the following solution:

app.enable('trust proxy');
...
console.log(req.ip);                        // gives ::ffff:127.0.0.1
console.log(req.ips);                       // gives []
console.log(req.header('x-forwarded-for')); // gives undefined 
console.log(req.connection.remoteAddress);  // gives ::ffff:127.0.0.1

Is there any other way?

Is this a symptom of a bigger problem?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

If you want to use the X-Forwarded-For header then you need to set it with nginx first:

proxy_set_header X-Forwarded-For $remote_addr;

See the docs:

  • http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_set_header
about 4 years ago · Santiago Trujillo Report
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!