如何在NGINX服务器上使用Meteor提供多个React Native应用程序?

时间:2016-12-13 01:23:48

标签: node.js ubuntu meteor nginx react-native

我正在尝试配置具有多个端口和proxy_pass参数的NGINX服务器,以便我的服务器可以处理多个Meteor / React Native应用程序。我的RN应用程序连接

let METEOR_URL = 'ws://52.X.XXX.168/websocket';//<=or 168:80/websocket
Meteor.connect(METEOR_URL);

只有在我没有指定端口或指定端口80时才有效。我正在使用

部署我的应用程序
ROOT_URL=http://localhost PORT=3030 MONGO_URL=mongodb://localhost:27017/MyApp node /home/ubuntu/myapp/bundle/main.js

(但也尝试使用ROOT_URL = http://localhost:8010) 这一切都有效。但是如果我尝试以任何方式运行第二个应用程序,我就会遇到麻烦。我已经在我的nginx.conf中尝试了多个服务器上游块,多个服务器块具有不同的侦听端口,但我永远不能将RN应用程序中的METEOR_URL更改为其他端口并让RN应用程序获取任何数据(获取错误' “mydata”没有订阅。)

我的nginx.conf看起来大致如此,我尝试过的东西已经注释掉了:

map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}
# HTTP
#upstream app {
#    server 172.0.0.132:3030;
#    server 172.0.0.132:3060;
#}

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;
    #listen 3030;
    #listen 3060;
    listen 3090;


    # pass requests to Meteor
    location / {
        proxy_pass http://localhost:3030; # or 'app' if using upstream block

        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade; #for websockets
        proxy_set_header Connection $connection_upgrade;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $host;
    }

  root /var/www/html;
  server_name localhost;
}

server {
  listen 3060;
server_name  MyApp;
# pass requests to Meteor
    location / {
        proxy_pass http://localhost:3030;

    proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade; #for websockets
        proxy_set_header Connection $connection_upgrade;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $host;
    }

}

对于我应该如何处理此事的任何建议都将不胜感激!

1 个答案:

答案 0 :(得分:1)

我建议将Phusion Passenger与nginx一起用于Meteor,它的设置非常简单,他们的教程/入门非常好:

https://www.phusionpassenger.com/library/install/nginx/install/oss/

它将保持流星运行,并且可以根据需要在端口80/443上运行所有内容