ELB-Nginx Proxy서버로 AccessLog 관리하기 (CLI)

CLI 계정 설정

aws configure  (Region:설정필요)

ELB policy 리스트

sudo aws elb describe-load-balancer-policy-types

ELB policy 만들기

aws elb create-load-balancer-policy --load-balancer-name <elb:name> --policy-name <ABC-policy> --policy-type-name ProxyProtocolPolicyType --policy-attributes AttributeName=ProxyProtocol,AttributeValue=true

ELB policy 확인

aws elb describe-load-balancer-policies --load-balancer-name <elb:name>

ELB에서 backend-server policy 설정

aws elb set-load-balancer-policies-for-backend-server --load-balancer-name <elb:name> --instance-port 80 --policy-names <ABC-policy>

EC2에서 Nginx 설정

vim /etc/nginx/nginx.conf
http {
    log_format  main  '$proxy_protocol_addr - $remote_user [$time_local] "$request" '

server {
        listen       80 proxy_protocol;
        listen       [::]:80 proxy_protocol;
        set_real_ip_from 10.0.0.0/16;
        real_ip_header proxy_protocol;
        server_name  _;
systemctl restart nginx

이제 AccessLog에서 ELB를 통한 접근 IP도 기록된다.

tail -f /var/log/nginx/access.log