我很难使用 Meteor-up 以 https 和 NGINX 作为代理将我的 Meteor 应用程序(下面的“myApp”)部署到生产环境中。特别是,我认为我在配置正确的端口和/或路径时遇到问题。
该部署在大多数方面都发挥了作用。它在带有 mongohq(现在的 compose.io)数据库的数字海洋水滴上运行。我的mup setup
, mup reconfig
(现在在我的 mup.json 文件上运行多次)并且mup deploy
使用meteor-up的命令都没有报告错误。如果我 ssh 进入数字海洋上的 ubuntu 环境并运行status myApp
它报道myApp start/running, process 10049
,当我检查我的 mongohq 数据库时,我可以看到 myApp 的预期集合已创建并播种。我认为在此基础上该应用程序运行正常。
我的问题是,我无法在访问该站点时找到它,并且没有使用 NGINX 服务器的经验,我无法判断我是否在做一些非常基本且错误的设置端口和转发的操作。
我在下面复制了 NGINX 配置文件和 mup.json 文件的相关部分。
我的行为expected通过下面的设置,如果我的 Meteor 应用程序侦听 mup.json 中的端口 3000,则当我访问该网站时,该应用程序应该会出现。事实上,如果我将 mup.json 的 env.PORT 设置为 3000,当访问该站点时,我的浏览器会告诉我存在重定向循环。如果我将 mup 的 env.PORT 更改为 80,或者完全保留 env.PORT,我会收到502 Bad Gateway
消息 - 这部分是预期的,因为 myApp 应该在 localhost:3000 上侦听,并且我不希望在其他任何地方找到任何内容。
非常感谢所有帮助。
MUP.JSON(在相关部分,如果需要显示更多内容,lmk)
"env": {
"PORT": 3000,
"NODE_ENV": "production",
"ROOT_URL": "http://myApp.com",
"MONGO_URL": // working ok, not reproduced here,
"MONGO_OPLOG_URL": // working ok I think,
"MAIL_URL": // working ok
}
NGINX
server_tokens off;
# according to a digital ocean guide i followed here, https://www.digitalocean.com/community/tutorials/how-to-deploy-a-meteor-js-application-on-ubuntu-14-04-with-nginx, this section is needed to proxy web-socket connections
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
# HTTP
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
server_name myApp.com;
# redirect non-SSL to SSL
location / {
rewrite ^ https://$server_name$request_uri? permanent;
}
}
# HTTPS
server {
listen 443 ssl spdy;
# this domain must match Common Name (CN) in the SSL certificate
server_name myApp.com;
root html;
index index.html index.htm;
ssl_certificate /etc/nginx/ssl/tempcert.crt;
ssl_certificate_key /etc/nginx/ssl/tempcert.key;
ssl_stapling on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 5m;
ssl_prefer_server_ciphers on;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers 'long string I didn't reproduce here'
add_header Strict-Transport-Security "max-age=31536000;";
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
另请注意,SSL 证书已配置且工作正常,因此我认为这与端口、路径和转发的配置方式有关。我不知道重定向循环来自哪里。