프론트 엔 드 Nginx, 백 엔 드 아파 치가 사용자 의 실제 IP 주 소 를 가 져 옵 니 다.

21019 단어
최근 아파 치 - 2.2 와 아파 치 - 2.4 를 'lnmp 원 키 설치 패키지' 에 추가 한 결과, Nginx 는 프론트 엔 드, 아파 치 는 백 엔 드 인 경우, 아파 치 는 Nginx 프론트 엔 드 의 IP 주소 (127.0.0.0.1) 만 가 져 올 수 있 을 뿐 사용자 의 실제 IP 주 소 를 가 져 올 수 없다. 이 경우 백 엔 드 는 아파 치가 사용자 의 실제 IP 주 소 를 어떻게 가 져 오 는가?
Nginx 설정 은 다음 과 같 습 니 다.
location / {
        try_files $uri @apache;
        }

location @apache {
        internal;
        proxy_pass http://127.0.0.1:8080;
        include proxy.conf;
        }

location ~ .*\.(php|php5)?$  {
        proxy_pass http://127.0.0.1:8080;
        include proxy.conf;
        }
proxy_connect_timeout 300s;
proxy_send_timeout 900;
proxy_read_timeout 900;
proxy_buffer_size 32k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_redirect off;
proxy_hide_header Vary;
proxy_set_header Accept-Encoding '';
proxy_set_header Referer $http_referer;
proxy_set_header Cookie $http_cookie;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

실제 IP 주소 가 져 오기 Apache 모듈 2 개: modrpaf: 아파 치 - 2.2 지원;Apache - 2.4 는 지원 하지 않 습 니 다.인터넷 강좌 많은 modremoteip: Apache - 2.4 자체 모듈;아파 치 - 2.2 지원;추천 하 다.
Apache-2.2.25 mod_rpaf 모듈
wget http://stderr.net/apache/rpaf/download/mod_rpaf-0.6.tar.gz
tar -xzvf mod_rpaf-0.6.tar.gz
cd mod_rpaf-0.6/
/usr/local/apache/bin/apxs  -i -c -n mod_rpaf-2.0.slo mod_rpaf-2.0.c

아파 치 설정 추가
vi  /usr/local/apache/conf/httpd.conf
Include conf/extra/httpd-rpaf.conf

vi /usr/local/apache/conf/extra/httpd-rpaf.conf
LoadModule rpaf_module        modules/mod_rpaf-2.0.so
RPAFenable On
RPAFsethostname On
RPAFproxy_ips 127.0.0.1 10.8.0.110 #       ip  (       )
RPAFheader X-Forwarded-For

비고: RPAFproxyips 뒤에 프 록 시 서버 의 ip 주 소 를 추가 하고 몇 개의 테스트 를 작성 합 니 다.
# /usr/local/apache/bin/apachectl -t
# /usr/local/apache/bin/apachectl restart
#    

mod_remoteip 아파 치 - 2.2 아래 mod 설정remoteip 은 다음 과 같 습 니 다: 설치
wget https://github.com/ttkzw/mod_remoteip-httpd22/raw/master/mod_remoteip.c
/usr/local/apache/bin/apxs -i -c -n mod_remoteip.so mod_remoteip.c

프로필 수정:
vi /usr/local/apache/conf/httpd.conf
Include conf/extra/httpd-remoteip.conf
vi /usr/local/apache/conf/extra/httpd-remoteip.conf
LoadModule remoteip_module modules/mod_remoteip.so
RemoteIPHeader X-Forwarded-For
RemoteIPInternalProxy 127.0.0.1

테스트:
# /usr/local/apache/bin/apachectl -t
# /usr/local/apache/bin/apachectl restart
#    

아파 치 - 2.4 설정 modremoteip 위 (자체 mod remoteip 모듈 은 설치 할 필요 가 없습니다) 를 제외 하고 로그 형식 도 수정 해 야 합 니 다.
LogFormat "%h %a %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %a %l %u %t \"%r\" %>s %b" common
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedi

로그 형식 에% a 추가

좋은 웹페이지 즐겨찾기