So I have Nginx proxy and some servers running behind it. I need to know real users IP not proxy, so I using real_ip module. Everything is working as expected, but if I configure vhost like subdomain.domain.com backend getting Nginx proxy IP.

Here is my Nginx config sample

set_real_ip_from  192.168.2.0/24;
real_ip_header    X-Forwarded-For;
real_ip_recursive on;

upstream srv1 { server 192.168.2.12:80; }

server {

        listen       80;
        server_name  dev.somedomain.com;

        location / {
         proxy_pass  http://srv1;
       }

}

server {

        listen       80;
        server_name  somedomain.com;

        location / {
          proxy_pass  http://srv1;
        }

}

So if I go to somedomain.com backend receiving real IP, no problems here. But for dev.somedomain.com backend receiving proxy IP!

And this is only shortened example, same situation with different domains and subdomains...

I just don't see whats is wrong here...

  • Requests to somedomain.com are going directly to upstream. Requests to the subdomain are going to nginx. Upstream has to process the X-Forwarded-For header for it to get the original client ip. – Jonah Benton Aug 27 '16 at 22:12
  • I don't get it, I mean I know this, but I doing it already in first 3 lines of example...Or I don't get what you tried to say. – RomkaLTU Aug 28 '16 at 8:04

Ok so it seams my mistake, everything is fine with this configuration, I need extra step in backend to complete my task, as for specific example I needed to set option in backend server (litespeed web server) option "Use Client IP in Header" I must be accidentally disabled it.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.