Vesta Control Panel - Forum

Community Forum

Skip to content

Advanced search
  • Quick links
    • Main site
    • Github repo
    • Google Search
  • FAQ
  • Login
  • Register
  • Board index Main Section General Discussion
  • Search

Original visitors IP X forwarded Headers

General questions about VestaCP
Post Reply
  • Print view
Advanced search
13 posts
  • 1
  • 2
  • Next
RouterRat
Posts: 23
Joined: Sat Dec 06, 2014 12:20 am

Original visitors IP X forwarded Headers
  • Quote

Post by RouterRat » Sat Dec 06, 2014 6:55 am

So I have a test page like this called test.php to show visitor's IP address. How ever it's showing server's internal IP.

<?php
echo $_SERVER['REMOTE_ADDR'];
?>

I tried to insert some values into local/ part of nginx.conf but did not work and didn't know where I am supposed to add it since there are few.

My question is a duplicate of this below I think.. but I can't understand how they fixed it. G.Translate is not helping
viewtopic.php?f=29&t=5106&p=12551&hilit=echo+$_SERVER['REMOTE_ADDR'];

Can you please tell me which one of these files I need to edit and add exactly what in there?

# sudo find / -name nginx.conf
/etc/nginx/nginx.conf
/usr/local/vesta/nginx/conf/nginx.conf
/usr/local/vesta/install/rhel/nginx.conf
/usr/local/vesta/install/rhel/monit/nginx.conf
/usr/local/vesta/install/debian/nginx.conf
/usr/local/vesta/install/ubuntu/nginx.conf
/usr/local/vesta/src/rpm/conf/nginx.conf
/home/admin/conf/web/nginx.conf

# sudo find / -name apache2.conf
/etc/apache2/apache2.conf
/usr/local/vesta/install/debian/apache2.conf
/usr/local/vesta/install/ubuntu/apache2.conf
/home/admin/conf/web/apache2.conf

I checked this http://vestacp.com/docs/#config-log-loc ... ian-ubuntu but it's kind of just showing me where all the files are.

I'd really appreciate that..

Thanks!
Top

joem
Posts: 378
Joined: Thu Nov 13, 2014 8:33 am

Os: CentOS 6x
Web: nginx + php-fpm
Re: Original visitors IP X forwarded Headers
  • Quote

Post by joem » Sat Dec 06, 2014 8:14 am

RouterRat wrote:So I have a test page like this called test.php to show visitor's IP address. How ever it's showing server's internal IP.

<?php
echo $_SERVER['REMOTE_ADDR'];
?>

I tried to insert some values into local/ part of nginx.conf but did not work and didn't know where I am supposed to add it since there are few.

My question is a duplicate of this below I think.. but I can't understand how they fixed it. G.Translate is not helping
viewtopic.php?f=29&t=5106&p=12551&hilit=echo+$_SERVER['REMOTE_ADDR'];

Can you please tell me which one of these files I need to edit and add exactly what in there?

# sudo find / -name nginx.conf
/etc/nginx/nginx.conf
/usr/local/vesta/nginx/conf/nginx.conf
/usr/local/vesta/install/rhel/nginx.conf
/usr/local/vesta/install/rhel/monit/nginx.conf
/usr/local/vesta/install/debian/nginx.conf
/usr/local/vesta/install/ubuntu/nginx.conf
/usr/local/vesta/src/rpm/conf/nginx.conf
/home/admin/conf/web/nginx.conf

# sudo find / -name apache2.conf
/etc/apache2/apache2.conf
/usr/local/vesta/install/debian/apache2.conf
/usr/local/vesta/install/ubuntu/apache2.conf
/home/admin/conf/web/apache2.conf

I checked this http://vestacp.com/docs/#config-log-loc ... ian-ubuntu but it's kind of just showing me where all the files are.

I'd really appreciate that..

Thanks!
Maybe this might help https://rtcamp.com/tutorials/nginx/forw ... s-real-ip/
Top

RouterRat
Posts: 23
Joined: Sat Dec 06, 2014 12:20 am

Re: Original visitors IP X forwarded Headers
  • Quote

Post by RouterRat » Sat Dec 06, 2014 3:07 pm

Hey thanks for the reply!

I actually gave this a try but here is where I am lost there are 3 recommendations here which I only tried 2nd.

1st change

Code: Select all

Nginx config from front-end proxy

proxy_set_header        X-Real-IP       $remote_addr;
proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
2nd change

Code: Select all

following lines inside backend-nginx conf:

location ~ \.php$ {
        fastcgi_param REMOTE_ADDR $http_x_real_ip;
        #...other rules
}
3rd change

Code: Select all

 by adding a line like below to your backend nginx-config:

        set_real_ip_from   192.168.122.1;
So which one am I supposed to do and in which nginx file?

# sudo find / -name nginx.conf
/etc/nginx/nginx.conf
/usr/local/vesta/nginx/conf/nginx.conf
/usr/local/vesta/install/rhel/nginx.conf
/usr/local/vesta/install/rhel/monit/nginx.conf
/usr/local/vesta/install/debian/nginx.conf
/usr/local/vesta/install/ubuntu/nginx.conf
/usr/local/vesta/src/rpm/conf/nginx.conf
/home/admin/conf/web/nginx.conf

Thanks!
Top

joem
Posts: 378
Joined: Thu Nov 13, 2014 8:33 am

Os: CentOS 6x
Web: nginx + php-fpm
Re: Original visitors IP X forwarded Headers
  • Quote

Post by joem » Sat Dec 06, 2014 4:20 pm

RouterRat wrote:Hey thanks for the reply!

I actually gave this a try but here is where I am lost there are 3 recommendations here which I only tried 2nd.

1st change

Code: Select all

Nginx config from front-end proxy

proxy_set_header        X-Real-IP       $remote_addr;
proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
2nd change

Code: Select all

following lines inside backend-nginx conf:

location ~ \.php$ {
        fastcgi_param REMOTE_ADDR $http_x_real_ip;
        #...other rules
}
3rd change

Code: Select all

 by adding a line like below to your backend nginx-config:

        set_real_ip_from   192.168.122.1;
So which one am I supposed to do and in which nginx file?

# sudo find / -name nginx.conf
/etc/nginx/nginx.conf
/usr/local/vesta/nginx/conf/nginx.conf
/usr/local/vesta/install/rhel/nginx.conf
/usr/local/vesta/install/rhel/monit/nginx.conf
/usr/local/vesta/install/debian/nginx.conf
/usr/local/vesta/install/ubuntu/nginx.conf
/usr/local/vesta/src/rpm/conf/nginx.conf
/home/admin/conf/web/nginx.conf

Thanks!
Dependings on the nginx template you use for each client you find them under
/usr/local/vesta/data/templates/web/nginx
Top

RouterRat
Posts: 23
Joined: Sat Dec 06, 2014 12:20 am

Re: Original visitors IP X forwarded Headers
  • Quote

Post by RouterRat » Sat Dec 06, 2014 7:31 pm

So I left everything on default. It's fresh out of the box..

First I need to find if I am using "front-end proxy" or "backend-nginx conf" correct?

After that if I am using front-end proxy I have to add
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

and if I am using back-end nginx conf I need to add a rule like this

location ~ \.php$ {
fastcgi_param REMOTE_ADDR $http_x_real_ip;
#...other rules
}


Do I still need to do this in back end nginx config?

set_real_ip_from 192.168.122.1; -- my local ip


Are these correct statemets?
Top

RouterRat
Posts: 23
Joined: Sat Dec 06, 2014 12:20 am

Re: Original visitors IP X forwarded Headers
  • Quote

Post by RouterRat » Sat Dec 06, 2014 11:50 pm

So can you tell me if I have a www.example.com

Where is front-end nginx config and where is back-end nginx config for this domain on default settings for VestaCP?
Top

RouterRat
Posts: 23
Joined: Sat Dec 06, 2014 12:20 am

Re: Original visitors IP X forwarded Headers
  • Quote

Post by RouterRat » Sun Dec 07, 2014 12:23 am

So my client is using the "default"

I changed both /usr/local/vesta/data/templates/web/nginx/default.tpl and default.stpl

To this, does it look correct?
If this looks correct where is the other file where I have to put down the IP?

Code: Select all

server {
    listen      %ip%:%proxy_port%;
    server_name %domain_idn% %alias_idn%;
    error_log  /var/log/%web_system%/domains/%domain%.error.log error;

    location / {
        proxy_pass      http://%ip%:%web_port%;
        location ~* ^.+\.(%proxy_extentions%)$ {
            proxy_set_header        X-Real-IP       $remote_addr;
            proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
            root           %docroot%;
            access_log     /var/log/%web_system%/domains/%domain%.log combined;
            access_log     /var/log/%web_system%/domains/%domain%.bytes bytes;
            expires        max;
            try_files      $uri @fallback;
        }
    }

    location /error/ {
        alias   %home%/%user%/web/%domain%/document_errors/;
    }

    location @fallback {
        proxy_pass      http://%ip%:%web_port%;
    }

    location ~ /\.ht    {return 404;}
    location ~ /\.svn/  {return 404;}
    location ~ /\.git/  {return 404;}
    location ~ /\.hg/   {return 404;}
    location ~ /\.bzr/  {return 404;}

    include %home%/%user%/conf/web/nginx.%domain%.conf*;
}
Top

joem
Posts: 378
Joined: Thu Nov 13, 2014 8:33 am

Os: CentOS 6x
Web: nginx + php-fpm
Re: Original visitors IP X forwarded Headers
  • Quote

Post by joem » Sun Dec 07, 2014 3:12 am

RouterRat wrote:So my client is using the "default"

I changed both /usr/local/vesta/data/templates/web/nginx/default.tpl and default.stpl

To this, does it look correct?
If this looks correct where is the other file where I have to put down the IP?

Code: Select all

server {
    listen      %ip%:%proxy_port%;
    server_name %domain_idn% %alias_idn%;
    error_log  /var/log/%web_system%/domains/%domain%.error.log error;

    location / {
        proxy_pass      http://%ip%:%web_port%;
        location ~* ^.+\.(%proxy_extentions%)$ {
            proxy_set_header        X-Real-IP       $remote_addr;
            proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
            root           %docroot%;
            access_log     /var/log/%web_system%/domains/%domain%.log combined;
            access_log     /var/log/%web_system%/domains/%domain%.bytes bytes;
            expires        max;
            try_files      $uri @fallback;
        }
    }

    location /error/ {
        alias   %home%/%user%/web/%domain%/document_errors/;
    }

    location @fallback {
        proxy_pass      http://%ip%:%web_port%;
    }

    location ~ /\.ht    {return 404;}
    location ~ /\.svn/  {return 404;}
    location ~ /\.git/  {return 404;}
    location ~ /\.hg/   {return 404;}
    location ~ /\.bzr/  {return 404;}

    include %home%/%user%/conf/web/nginx.%domain%.conf*;
}
For the above code I would put
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
below
location / {
proxy_pass http://%ip%:%web_port%;
Place

Code: Select all

set_real_ip_from
in /etc/nginx/nginx.conf. Just by looking at it I cant tell 100% you just have to try it. If you dont want to rebuild all the users you can try it just for one user by adding the code I quoted above in /home/admin/conf/web/nginx.conf instead of adding it to /usr/local/vesta/data/templates/web/nginx/default.tpl. Change admin with the users you want to try it on. If you do use /usr/local/vesta/data/templates/web/nginx/default.tpl you need to toggle all users and rebuild web.
Top

RouterRat
Posts: 23
Joined: Sat Dec 06, 2014 12:20 am

Re: Original visitors IP X forwarded Headers
  • Quote

Post by RouterRat » Sun Dec 07, 2014 8:17 pm

Hey thank you for the answer I just did the changes I have few other questions though.

It's OK for me to change default.tpl and default.stpl since it will not make that much of a difference.
you need to toggle all users and rebuild web.
How do toggle all users and rebuild web?

Also my server has two private IP that are not public IPs I do nat, what IP will be used here the local IP which is what's assigned to the site or a public IP?
set_real_ip_from
Top

joem
Posts: 378
Joined: Thu Nov 13, 2014 8:33 am

Os: CentOS 6x
Web: nginx + php-fpm
Re: Original visitors IP X forwarded Headers
  • Quote

Post by joem » Mon Dec 08, 2014 2:04 am

RouterRat wrote:How do toggle all users and rebuild web?
Login Vesta CP -> Click Users Tab -> Next to add user is "Toggle All Users" click it -> Next to that is a drop down menu -> Select rebuild web -> click the little button next to that.
RouterRat wrote:Also my server has two private IP that are not public IPs I do nat, what IP will be used here the local IP which is what's assigned to the site or a public IP?

I really would need to see a phpinfo page to answer that. But my best guess would be use the public IP or you could add all the ips and remove them one by one to see which ones work.
Top


Post Reply
  • Print view

13 posts
  • 1
  • 2
  • Next

Return to “General Discussion”



  • Board index
  • All times are UTC
  • Delete all board cookies
  • The team
Powered by phpBB® Forum Software © phpBB Limited
*Original Author: Brad Veryard
*Updated to 3.2 by MannixMD
 

 

Login  •  Register

I forgot my password