Lucee returns Proxy IP from nginx

Hi,
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.

Lucee

Ubuntu 20.04
apache 2.4.41
Lucee 5.3.7.43
Apache Tomcat/9.0.35

Proxy

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

Lucee/Tomcat

/opt/lucee/tomcat/conf/server.xml

Nginx

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!

regards
Carsten

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.

HTH

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!