nginx - 使用 Meteor-Up、SSL 和 NGINX 将 Meteor 部署到生产环境

标签 nginx meteor meteor-up

我在使用meteor-up 和https 和NGINX 作为代理将我的meteor 应用程序(下面的“myApp”)部署到生产中时遇到了困难。特别是,我认为我无法配置正确的端口和/或路径。

部署在大多数方面都奏效了。它运行在带有 mongohq(现在是 compose.io)数据库的 digital ocean 液滴上。我的 mup setup , mup reconfig (现在在我的 mup.json 文件上运行多次)和 mup deploy带有meteor-up 的命令都没有报告错误。如果我在 digital ocean 上通过 ssh 进入我的 ubuntu 环境并运行 status myApp它报告myApp start/running, process 10049 ,当我检查我的 mongohq 数据库时,我可以看到 myApp 的预期集合被创建和播种。我认为在此基础上该应用程序运行正常。

我的问题是我无法在访问该站点时找到它,并且没有使用 NGINX 服务器的经验,我无法判断我是否在做一些非常基本和错误的设置端口和转发的操作。

我已经在下面复制了我的 NGINX 配置文件和 mup.json 文件的相关部分。

我在下面的设置中预期的行为是,如果我的 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 证书已配置且工作正常,因此我认为这与端口、路径和转发的配置方式有关。我不知道重定向循环来自哪里。

最佳答案

对于将来遇到此问题的任何人,我可以通过删除 force-ssl 来解决问题。来自我捆绑的 meteor 应用程序的包。显然 force-ssl 和 NGINX 代理要么是多余的,要么一起使用会导致过多的重定向。这在我找到的 Material 中没有得到很好的记录。

如果有一个配置支持将 force-ssl 与一个用于某些目的的代理一起使用并且比完全删除包更可取,请发布,因为我有兴趣知道。谢谢。

关于nginx - 使用 Meteor-Up、SSL 和 NGINX 将 Meteor 部署到生产环境,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26936433/

相关文章:

ruby-on-rails - 使用带有 Rails 的 X-Accel-Redirect 创建 POST 请求?

ruby-on-rails - 乘客 EBADF 文件描述符异常 502

javascript - 尽管设置了 header ,但 CORS 不起作用

javascript - Meteor 嵌套 View 和产量

meteor - 如何在不同的端口上运行多个 meteor 服务器

nginx - Nginx在上游响应日志中显示2种不同的状态

javascript - 无法从 Meteor 服务器端接收已发布的集合

meteor - 在 Iron-Router 中为相同的 URL 推送新状态

deployment - 在 Meteor Up 中如何设置 MONGO_OPLOG_URL?

docker - Mup安装失败,显示 “endpoint with name mongodb already exists in network bridge”