서버를 많이 추가할 경우 server_names_hash_bucket_size 관련 오류가 발생할 수 있다. 이때는 해당 값을 늘려준다.
http {
server_names_hash_bucket_size 64;
}
/example 컨텍스트를 www.example.com으로 연동하고자 할 때 다음과 같이 선언한다.server {
server_name www.example.com;
location / {
proxy_pass http://localhost:8000/example/;
proxy_redirect http://www.example.com/example/ http://www.example.com/;
proxy_cookie_path /example /;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr; # ELB 등 중간자가 또 있을 경우에도 제대로 작동할까?
proxy_set_header Host $host;
proxy_read_timeout 60s; # 응답을 읽기까지의 타임아웃. send_timeout 과 함께 조정
}
}
<Connector/>는 Apache Proxy Module와 같다.<!-- proxyName 과 proxyPort를 지정해야만 한다. --> <Connector port="8080" protocol="HTTP/1.1" redirectPort="8443" /> <!-- proxy_set_header의 Host 설정으로 proxyName="www.example.com" proxyPort="80" 제외 -->
X-Forwarded-For 헤더에 저장해야하며, 이를 통해 해당 헤더의 첫번째 값으로 요청을 보낸 클라이언트의 IP 주소를 알 수 있다.X-Forwarded-For 헤더를 구성하지만 nginx는 직접 구성해줘야 한다.proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
$upstream_http_[headername]이 응답 헤더 내용을 저장한 변수이다.$http_[requestHeaderName]이 요청 헤더 내용을 저장한 변수이다.