본문 바로가기

리눅스

[리눅스] nginx에서 X-Forwarded-For(XFF) 설정하는 방법

728x90

nginx에서 X-Forwarded-For(XFF) 설정하는 방법

nginx는 X-Forwarded-For 헤더를 사용하여 클라이언트의 실제 IP 주소를 확인할 수 있다.

nginx 설정 파일 편집

  • set_real_ip_from <trusted IP address>;
  • real_ip_header X-Forwarded-For;
sudo vim /etc/nginx/nginx.conf
http {
    ...
    set_real_ip_from 0.0.0.0/0; 
    real_ip_header X-Forwarded-For;
    ...
}

nginx 설정(nginx.conf) 파일 문법 검사

nginx -t
$ nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

nginx 서비스 다시 시작

systemctl restart nginx
728x90