Reputation: 543
Previously when I was using Nginx -> Node script only, I was able to get the visitor's real IP address using an Nginx config like this:
location / {
proxy_pass http://localhost:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
But now, everything is behind a Digital Ocean Load Balancer. As a result, the node script receives the Digital Ocean Load Balancer's IP address.
Have any of your experienced this before, and how did you solve it?
Cheers.
Upvotes: 2
Views: 3264
Reputation: 543
I solved this.
With Digital Ocean load balancers, if you use "passthrough" for the load balancer -> droplet setup, it won't pass the client IP.
You need to configure the load balancer (via the Digital Ocean UI) to use a "new certificate" (it can be any certificate).
So the DO load balancer setup will be HTTPS/443 -> new certificate -> HTTPS/443.
I believe this is called terminating the SSL connection at the load balancer.
Upvotes: 5
Reputation: 1692
DigitialOcean Load Balancers set the X-Forwarded-For, X-Forwarded-Proto, and X-Forwarded-Port
In your case :
proxy_set_header X-Real-IP $http_x_forwarded_for
Upvotes: 3