10

Nginxを使用して、複数のnode.jsを1つのサーバーで実行できることを理解しています.Meteorを拡張すると思います。Nginx をセットアップして Ubuntu サーバーで問題なく実行しています。リクエストに応答して、それらを私のアプリケーションにプロキシすることもできます。ただし、Nginx でトラフィックを 2 番目のアプリケーションにプロキシしようとすると、障害が発生しました。

背景:

  • ポート 8001 で実行されている最初のアプリ
  • ポート 8002 で実行されている 2 番目のアプリ
  • ポート80でリッスンするNginx
  • nginx に / のトラフィックをアプリ 1 に送信させ、/app2/ のトラフィックをアプリ 2 に送信させようとしています
  • domain:8001 と domain: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/ に移動したときに何が起こっているのかについての洞察をいただければ幸いです。

4

2 に答える 2

0

Nginx の代替手段を探している人: Meteor アプリごとにクラスター パッケージをインストールすると、パッケージが自動的に負荷分散を処理します。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

セットアップ例:

{
  "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"
  }
}
于 2016-05-26T11:42:10.907 に答える