Lucee returns Proxy IP from nginx

we use nginx plus as Proxy in front of for Apache/Lucee.

Problem is, that cgi.remote_addr or getpagecontext().getrequest().getRemoteAddr() returns IP from nginx proxy, not from Client.


Ubuntu 20.04
apache 2.4.41
Apache Tomcat/9.0.35


Ubuntu 20.04
nginx/1.19.5 (nginx-plus-r23)




proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;

I tried since yesterday, but i dont get further. Perhaps anyone can help me!


Your NGINX is setting headers X-Forwarded-For and X-Real-IP which will contain the end user’s IP so you’ll probably want to use the getHttpRequestData() function so you’ll be able to read them e.g.:

// Get the HTTPRequest to get IP addresses
Request.HTTPRequest = getHttpRequestData();
Request.IP = listFirst((Request.HTTPRequest.Headers["X-Forwarded-For"] ?: ""));

However, the caveat here is that we use NGINX to proxy directly to Lucee. From your Lucee set up are you then using Apache to talk to Lucee? If so, you might need to tweak some Apache settings to pass these headers through.


Thank you jedihomer, but the problem is the same.
It seems like an problem in nginx config. i testet with another subdomain on same proxy and lucee server and remote_addr seems fine. :frowning:

I tried to change nginx-config and after i changed
-proxy_set_header Host
+#proxy_set_header Host

everything is fine and i can see geoip_country_code too!

Thank you very much!