简体   繁体   中英

nginx does not set remote clients ip address

I want to get the IP address of the client that visits my page. My app is running behind a proxy so I set this configuration to my nginx file:

proxy_set_header X-Forwarded-For $remote_addr;

Now I try to get the IP address like this in express

req.ip
req.headers["x-forwarded-for"]
req.ips
req.connection.remoteAdress

Nothing seems to work. I also set trust proxy to true

app.set("trust proxy", true);

But the other configuration like proxy_set_header Host or proxy_set_header Connection "upgrade" are working.

What am I doing wrong?

Well the problem was that i have 2 applications running behind my proxy and i set the configuration on the wrong proxy.

I had to scroll down.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM