2013-04-29 2 views
10

Nenex를 사용하여 하나의 서버에서 여러 개의 node.js 및 확장 Meteor를 사용할 수 있다고 생각합니다. 나는 Nginx 설정을 가지고 있고 우분투 서버에서 잘 돌아가고있다. 심지어 요청에 응답하고 그것을 내 응용 프로그램 하나에 프록시로 보낼 수있다. 그러나 Nginx가 두 번째 애플리케이션에 대한 트래픽을 프록시 처리하려고 할 때로드 블록을 맞았습니다. Nginx 및 다중 Meteor/Nodejs 응용 프로그램에 문제가 있습니다

일부 배경 :

  • 1 응용 프로그램 /에 트래픽을 보내 nginx를 얻기 위해 시도 포트 8001
  • 2 응용 프로그램 포트에서 실행 8002
  • Nginx의 포트에서 수신 80
  • 에서 실행되는 앱 하나 및/app2 /의 트래픽을 앱 2에 전송
  • 도메인 : 8001 및 도메인 : 8002
로 이동하면 두 앱에 연결할 수 있습니다

내 Nginx에의 설정 :

upstream mydomain.com { 
server 127.0.0.1:8001; 
server 127.0.0.1:8002; 
} 

# the nginx server instance 
server { 
listen 0.0.0.0:80 default_server; 
access_log /var/log/nginx/mydomain.log; 

location /app2 { 
    rewrite /app2/(.*) /$1 break; 
    proxy_set_header X-Real-IP $remote_addr; 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_set_header Host $http_host; 
    proxy_set_header X-NginX-Proxy true; 
    proxy_pass http://127.0.0.1:8002; 
    proxy_redirect off; 
    proxy_http_version 1.1; 
    proxy_set_header Upgrade $http_upgrade; 
    proxy_set_header Connection "upgrade"; 
} 

location/{ 
    proxy_set_header X-Real-IP $remote_addr; 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_set_header Host $http_host; 
    proxy_set_header X-NginX-Proxy true; 
    proxy_pass http://127.0.0.1:8001; 
    proxy_redirect off; 
    proxy_http_version 1.1; 
    proxy_set_header Upgrade $http_upgrade; 
    proxy_set_header Connection "upgrade"; 
} 
} 

트래픽/APP2/나는 그것을 대단히 감사하겠습니다로 전환 될 때에 갈 것처럼 어떤 통찰력!

답변

26
proxy_pass http://127.0.0.1:8002/1; <-- these should be 
proxy_pass http://**my_upstream_name**; <--these 

다음

upstream my_upstream_name { 

//Ngixn do a round robin load balance, some users will conect to/and othes to /app2 

server 127.0.0.1:8001; 

server 127.0.0.1:8002; 

} 

프록시 제어 몇 팁 :

여기

다음을 살펴 here @nginx 문서 등을

을 우리가 갈 :

가중치 = NUMBER - 설정되지 않은 경우 서버의 가중치가 설정됩니다. 기본 라운드 로빈을 불균형시킵니다.

max_fails = NUMBER -가 작동 불능 간주 후 (파라미터 fail_timeout 할당) 기간 내에 서버와의 통신에 실패한 시도의 횟수. 설정되지 않은 경우 시도 횟수는 1입니다. 값이 0이면이 확인이 해제됩니다. 실패로 간주되는 것은 proxy_next_upstream 또는 fastcgi_next_upstream에 의해 정의됩니다 (max_fails로 계산되지 않는 http_404 오류 제외).

fail_timeout = TIME - 그 동안 * max_fails 발생해야하는 시간 * 서버가 작동하지 고려하고, 또한 시간이있는 서버가 작동하지 간주됩니다 원인이 서버와의 통신에 실패한 시도의 수 (다른 시도가 있기 전에). 설정되지 않은 경우 시간은 10 초입니다. fail_timeout은 업스트림 응답 시간과 아무 관련이 없으며이를 제어하기 위해 proxy_connect_timeout 및 proxy_read_timeout을 사용하십시오.

아래로 - 서버를 영구적으로 오프라인으로 표시하여 ip_hash 지시문과 함께 사용합니다.

백업 - (0.6.

U 경우 : 비 백업 서버가 모두 다운 또는 바쁜() 지시어 ip_hash와 함께 사용할 수없는 경우 7 이상)에만이 상점

EXAMPLE generic 

    upstream my_upstream_name { 
     server backend1.example.com weight=5; 
     server 127.0.0.1:8080   max_fails=3 fail_timeout=30s; 
     server unix:/tmp/backend3; 
    } 
// proxy_pass http://my_upstream_name; 

는 당신이 필요로하는 무엇을이 서버를 사용 하나의 응용 프로그램에 대한 가상 호스트 사이 드 부하를 제어하려는 :

upstream my_upstream_name{ 
      server 127.0.0.1:8080   max_fails=3 fail_timeout=30s; 
      server 127.0.0.1:8081   max_fails=3 fail_timeout=30s; 
      server 127.0.0.1:8082   max_fails=3 fail_timeout=30s; 
      server 127.0.0.1:8083 backup; 
// proxy_pass http://my_upstream_name; 
// amazingness no.1, the keyword "backup" means that this server should only be used when the rest are non-responsive 
    } 

u는 2 개 이상의 응용 프로그램이있는 경우 : 응용 프로그램 당 1 상류와 같은 :

,536,
upstream my_upstream_name{ 
       server 127.0.0.1:8080   max_fails=3 fail_timeout=30s; 
       server 127.0.0.1:8081   max_fails=3 fail_timeout=30s; 
       server 127.0.0.1:8082   max_fails=3 fail_timeout=30s; 
       server 127.0.0.1:8083 backup; 
      } 
upstream my_upstream_name_app2 { 
       server 127.0.0.1:8084   max_fails=3 fail_timeout=30s; 
       server 127.0.0.1:8085   max_fails=3 fail_timeout=30s; 
       server 127.0.0.1:8086   max_fails=3 fail_timeout=30s; 
       server 127.0.0.1:8087 backup; 
      } 
upstream my_upstream_name_app3 { 
       server 127.0.0.1:8088   max_fails=3 fail_timeout=30s; 
       server 127.0.0.1:8089   max_fails=3 fail_timeout=30s; 
       server 127.0.0.1:8090   max_fails=3 fail_timeout=30s; 
       server 127.0.0.1:8091 backup; 
      } 

도움이 되길 바랍니다.

+2

! upvote :) –

+0

그것은 놀라운 대답, 고마워요. 내 유일한 질문은 라운드 로빈 (부분적으로 언급 한)을 수행하려고하지 않는다는 것입니다. 올바른 업스트림 항목을 추가 하겠지만 호기심이 ... 내 위치 항목은 괜찮습니까? – jak119

+0

다음을 권장합니다. app1이 핵심 앱이고 app2가 'app1의 하위'인 경우 ur 위치는 괜찮습니다./app1과/app2 모두에 둘 수 있습니다. Boll – jmingov

0

Nginx의 대안을 찾는 사람들 : Meteor app마다 클러스터 패키지를 설치하면 패키지가 자동으로로드 밸런싱을 처리합니다. https://github.com/meteorhacks/cluster

를 설정하는 방법 :

# You can use your existing MONGO_URL for this 
export CLUSTER_DISCOVERY_URL=mongodb://host:port/db, 
# this is the direct URL to your server (it could be a private URL) 
export CLUSTER_ENDPOINT_URL=http://ipaddress 
# mark your server as a web service (you can set any name for this) 
export CLUSTER_SERVICE=web 

예 설정을 :

바로 여기에 하나 sweeeeet의 대답이다
{ 
    "ip-1": { 
    "endpointUrl": "http://ip-1", 
    "balancerUrl": "https://one.bulletproofmeteor.com" 
    }, 
    "ip-2": { 
    "endpointUrl": "http://ip-2", 
    "balancerUrl": "https://two.bulletproofmeteor.com" 
    }, 
    "ip-3": { 
    "endpointUrl": "http://ip-3", 
    "balancerUrl": "https://three.bulletproofmeteor.com" 
    }, 
    "ip-4": { 
    "endpointUrl": "http://ip-4" 
    } 
} 
관련 문제