Donate to support Ukraine's independence.
Generated by AI

Get Your Public IP Using Nginx

Public IP Address You can always use your own nginx instead of using 3rd party services when you need to know your public IP. Like this: # Public IP location = /ip { default_type text/plain; return 200 $remote_addr; } Or if you need it in JSON format like this: # Public IP JSON location = /ip_json { default_type application/json; return 200 "{\"ip\":\"$remote_addr\"}"; }

February 16, 2025 · 1 min · 63 words · Serhii Kaidalov
Generated by AI

Handling Real IP in Nginx Behind Load Balancer and Cloudflare

When running a website behind a load balancer and Cloudflare, handling client IPs in Nginx can be tricky. Different setups use different headers to pass the real IP: Custom Domains via Cloudflare: Cloudflare sends the real client IP in the CF-Connecting-IP header. Direct CNAME to Load Balancer: The load balancer sets the real client IP in the X-Forwarded-For header. What is the challenge? Nginx’s real_ip_header directive doesn’t support variables. This limitation means you can’t conditionally choose between headers like X-Forwarded-For and CF-Connecting-IP. ...

December 28, 2024 · 3 min · 526 words · Serhii Kaidalov