[Apache|Nginx] Reverse proxy Real IP

Front Nginx — Back Apache


Nginx

Setting Reverse Proxy with X-Real-IP

$ vi /etc/nginx/conf.d/<SomeReverseProxy>.conf

server {
    listen 80;

    server_name subdomain.silnex.kr;

    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;
}

 

Apache

Module Load

$ a2enmod remoteip

Create (or Edit) remoteip.conf 

$ vi /etc/apache2/conf-available/remoteip.conf

RemoteIPHeader X-Forwarded-For
RemoteIPTrustedProxy 127.0.0.1

than execute $ a2enconf remoteip

Edit apache2.conf(or httpd.conf)

$ vi /etc/apache/apache2.conf

## 수정 전 ##
#LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
#LogFormat "%h %l %u %t \"%r\" %>s %O" common 
## 수정 후 ##
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %O" common

Restart apache service

$ service apache2 restart

글의 문제가 있다면 댓글을 달아 주세요.

This site uses Akismet to reduce spam. Learn how your comment data is processed.