Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save trongnghia203/4a5e297eb00e2ad82338b29648ea306f to your computer and use it in GitHub Desktop.
Save trongnghia203/4a5e297eb00e2ad82338b29648ea306f to your computer and use it in GitHub Desktop.
Real IP for Apache (Nginx reverse proxy)

NGINX 1.10 + APACHE 2.4 real IP for reverse proxy

Edit nginx conf

default.conf or what you want

vim /etc/nginx/conf.d/default.conf

add proxy_set_header for php files

   location ~ \.php$ {
        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $host;

        proxy_pass   http://127.0.0.1:8080;
    }

Add apache remoteip mod with

a2enmod remoteip

create a new conf file for Apache

vim /etc/apache2/conf-available/remoteip.conf

and add

<IfModule mod_remoteip.c>
    RemoteIPHeader X-Forwarded-For
    RemoteIPTrustedProxy 127.0.0.1
</IfModule>

Add active this conf with

a2enconf remoteip

restart apache

service apache2 restart

And now apache logs and $SERVER['REMOTE_ADDR'] have the real IP ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment