Contenu | Rechercher | Menus

Annonce

Si vous avez des soucis pour rester connecté, déconnectez-vous puis reconnectez-vous depuis ce lien en cochant la case
Me connecter automatiquement lors de mes prochaines visites.

À propos de l'équipe du forum.

#1 Le 10/09/2015, à 02:06

abecidofugy

Nginx / Apache2 et $_SERVER[‘REMOTE_ADDR’]

Bonjour,

Sur un serveur dédié tournant sous Ubuntu Server 14.04 LTS, j'ai installé Vesta Control Panel (qui tourne très bien). Ça m'a configuré NGNIX en reverse proxy devant un Apache.

Ce fichier PHP est sensé me retourner l'adresse IP du visiteur :

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

Et bien ça m'affiche l'IP du serveur.

J'ai donc rajouté trois petites lignes dans le fichier suivant :

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

cat /usr/local/vesta/data/templates/web/nginx/default.tpl

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

    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://%ip%:%web_port%;

        location ~* ^.+\.(%proxy_extentions%)$ {
            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*;
}

cat /usr/local/vesta/data/templates/web/nginx/default.stpl

server {
    listen      %ip%:%proxy_ssl_port%;
    server_name %domain_idn% %alias_idn%;
    ssl         on;
    ssl_certificate      %ssl_pem%;
    ssl_certificate_key  %ssl_key%;
    error_log  /var/log/%web_system%/domains/%domain%.error.log error;

    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      https://%ip%:%web_ssl_port%;

        location ~* ^.+\.(%proxy_extentions%)$ {
            root           %sdocroot%;
            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      https://%ip%:%web_ssl_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/snginx.%domain%.conf*;
}

J'ai activé le template "default" dans mon admin Vesta, et j'ai reconstruits les droits :
1441812168.png

J'ai vérifié Apache :
cat /etc/apache2/mods-enabled/rpaf.conf

 
<IfModule rpaf_module>
    RPAFenable On

    # When enabled, take the incoming X-Host header and
    # update the virtualhost settings accordingly:
    RPAFsethostname On

    # Define which IP's are your frontend proxies that sends
    # the correct X-Forwarded-For headers:
RPAFproxy_ips 127.0.0.1 ::1 ADRESSEIPDUSERVEURCODEEENDUR

    # Change the header name to parse from the default
    # X-Forwarded-For to something of your choice:
#   RPAFheader X-Real-IP
</IfModule>

J'avais comme droits sur ce fichier : -rw-r--r--  1 root root  469 Nov  5  2014 rpaf.conf
J'ai donc fait un : sudo chmod 777 rpaf.conf

cat /etc/apache2/mods-enabled/rpaf.load

LoadModule rpaf_module /usr/lib/apache2/modules/mod_rpaf.so

service apache2 reload
service nginx reload

L'adresse IP ne change pas, c'est toujours celle du serveur.

Je me suis inspiré de ce tuto : http://blog.benjaminperrin.fr/index.php … mote_addr/

Merci de votre aide.

//EDIT : je ne suis pas sûr de l'emplacement des trois lignes dans le fichier de conf…

Dernière modification par abecidofugy (Le 10/09/2015, à 02:28)

Hors ligne