我正在尝试使用多个端口和 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 中尝试了多个服务器上游 block ,多个服务器 block 具有不同的监听端口,但我永远无法将 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 for Meteor,它很容易设置,而且他们的教程/入门非常好:
https://www.phusionpassenger.com/library/install/nginx/install/oss/
它将负责保持 meteor 运行,并可以根据需要在端口 80/443 上运行所有内容
关于node.js - 如何在 NGINX 服务器上使用 Meteor 服务多个 React Native 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41112342/