
nginx 서버에서 처리하는 3개의 애플리케이션 서버가 있습니다.
upstream he {
server h1.abc.example.com;
server h2.abc.example.com;
}
특정 헤더 값을 기반으로 요청을 리디렉션하는 방법은 무엇입니까? 예를 들어
abc-h1.abc.example.com should go to server
h1.abc.example.com
def-h1.abc.example.com should go to server
h2.abc.example.com
모든 요청의 위치는 동일합니다 -h1.abc.example.com
.
답변1
Nginx는 확실히 이 작업을 수행할 수 있습니다. 호스트별 헤더( server_name
)를 지정하고 업스트림을 분리하여 각 호스트에 하나씩 할당하기만 하면 됩니다.
다음과 같은 nginx 서버 조각이 작동할 수 있습니다(내 생각이며 테스트되지 않음).
upstream one { server h1.abc.example.com; }
upstream two { server h2.abc.example.com; }
server {
listen 8080;
server_name abc-h1.abc.example.com;
location / {
proxy_pass one;
}
}
server {
listen 8080;
server_name def-h1.abc.example.com;
location / {
proxy_pass two;
}
}
HTTP가 아닌 엔드포인트로 트래픽을 보내려는 경우 다른 프록시 핸들러( fastcgi_pass
, uwsgi_pass
, scgi_pass
, ) 가 있습니다.memcached_pass
편집: 오류 수정server_name