- Load Balancer->Attributes, X-Forwarded-For Header set to Append
- 在nginx中
server { # other configuration real_ip_header X-Forwarded-For; set_real_ip_from 0.0.0.0/0; location / { proxy_pass http://yourwebsite.com; # Overriding X-Forwarded-For with value of $remote_addr proxy_set_header X-Forwarded-For $remote_addr; } }
- 應用 (Node.js+Express)
app.get("/user_ip", (req, res) => { const ip = req.headers["x-forwarded-for"] || req.headers["x-real-ip"] || req.socket.remoteAddress; res.json({ ip: ip }); });