繁体   English   中英

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

[英]How can I serve multiple React Native apps with Meteor on NGINX server?

我正在尝试使用多个端口和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;
    }

}

任何有关我应该如何处理的建议,将不胜感激!

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM