2013-01-18 4 views
1

수신 포트 또는 server_name 대신 위치를 기반으로 nginx 프록시를 설정하고 싶습니다.위치 기반 Nginx 프록시

upstream cluster 
{ 
    server cluster1:8080; 
    server cluster2:8080; 
} 
server 
{ 
    listen 80; 
    server_name mydomain.com; 
    location /hbase 
    { 
     proxy_pass http://cluster; 
     proxy_set_header X-Real-IP $remote_addr; 
     proxy_next_upstream error timeout invalid_header http_500 http_502 http_503; 
    } 
} 

나는 이것이 정말 간단하다는 것을 알고 있습니다. 기본적으로 라우팅이 작동하는 것처럼 보이지만 실제로는 hbase 부분없이 서버로 트래픽을 라우팅해야하는 경우 "http : // cluster1 : 8080/hbase"를 호출합니다.

다시 쓰기 규칙이 적용되지만 nginx에서 다시 쓸 수있는 방법을 찾을 수없는 것 같습니다. 리디렉션하도록 설정할 수는 있지만 실제 포트가 외부 세계에 보이지 않도록해야합니다.

이 완벽하게 작동하지만, 난 단지 포트 80

upstream cluster 
{ 
    server cluster1:8080; 
    server cluster2:8080; 
} 
server 
{ 
    listen 555; 
    server_name mydomain.com; 
    location/
    { 
     proxy_pass http://cluster; 
     proxy_set_header X-Real-IP $remote_addr; 
     proxy_next_upstream error timeout invalid_header http_500 http_502 http_503; 
    } 
} 

에 트래픽이 가능하게 전달 된 요청에서 HBase를 제거하는 정규식을 사용하는 방법이 허용 할?

답 :

location /hbase 
{ 
    rewrite ^/hbase$|^/hbase/$|^/hbase/(.*)$ /$1 break; 
    proxy_pass http://cluster; 
} 

답변

1

효율적인 rewrite에서 의 nginx 있습니다. 다음은 작동해야합니다 (시도하지 않았 음)

location /hbase 
    { 
    rewrite ^.*$/break; 
    proxy_pass http://cluster; 
+0

감사합니다. 나는 그것을 시도했지만 정규식에 세 가지 사례 모두를 추가 할 생각이 아니었다. – Eulalie367

+0

오, 알았어,'/ hbase /'뒤에 뭔가가 있다는 것을 몰랐다. 다행이야! –