Page 1 of 1

Nginx - get real IP through X-Forwarded-For headers

Posted: Wed Apr 27, 2016 2:43 pm
by spacing
I run a mediawiki installation undera vestaCP and I need real ips to monitor contributions ip addresses, the problem is since I moved to a server with VestaCP all the contributions are listed under the same IP address which is the address of the server which I have tracked to be an issue related with nginx configuration and mediawiki supports that out of the box through this http://serverfault.com/questions/526547 ... 551#526551

The problem is that Im not very knowledgable in server stuff and I have been reading through nginx and vesta documentation and I haven't found the solution to nginx config

I have a SERVER_IP.conf which lists the following

Code: Select all

server {
    listen       SERVER_IP:SERVER_PORT default;
    server_name  _;
    #access_log  /var/log/nginx/SERVER_IP.log main;
    location / {
        proxy_pass  http://SERVER_IP:SERVER_PORT;
   }
}


server {
    listen 80;

    server_name comp.tf;

    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;

        proxy_pass http://127.0.0.1:4567/;
        proxy_redirect off;

        # Socket.IO Support
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}
I assume the problem is there and I want to be able to pass the real ip to media wiki through the X-Forwarded-For headers. How do I do that?

Re: Nginx - get real IP through X-Forwarded-For headers

Posted: Sat Apr 30, 2016 3:29 pm
by spacing
any help?

Re: Nginx - get real IP through X-Forwarded-For headers

Posted: Mon May 02, 2016 7:11 pm
by Falzo
you're on the right track at least. every request made is received by nginx which serves as a reverse proxy in front of your apache installation.

easiest way to get rid of that problem would be to switch of proxy support for your affected domain within vesta.
depending on your needs you wouldn't benefit from fast loading static-files via nginx after that change...

if you prefer to run that proxied setup you should look into configuring the domain-related config file (probably the SERVER_IP.conf would help that much) to something like:

Code: Select all

    location / {
        proxy_set_header    Host			$host;
        proxy_set_header    X-Real-IP		$remote_addr;
        proxy_set_header    X-Forwarded-For   $proxy_add_x_forwarded_for;
        proxy_pass  http://SERVER_IP:SERVER_PORT;
    }
be advised that vesta will overwrite changes to the domain-related files whenever something is changed on the domain-settings via controlpanel, so you probably need to make that changes in the template for the web-config you are running.
even adding this in the included file for custom changes won't work, as you can't define the /location block a second time.