Jer*_* S. 7 nginx meteor meteor-up
我使用meps-up以https和NGINX作为代理,将我的meteor应用程序(下面的"myApp")部署到生产中很困难.特别是,我认为我在配置正确的端口和/或路径时遇到了问题.
部署在大多数方面都有效.它运行在带有mongohq(现在的compose.io)数据库的数字海洋液滴上.我的mup setup,mup reconfig(上运行我的mup.json文件现在许多倍),mup deploy与流星的所有报告没有错误的命令.如果我在数字海洋上进入我的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上侦听,我不希望在其他任何地方找到任何东西.
所有帮助都非常感谢.
"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
}
Run Code Online (Sandbox Code Playgroud)
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;
}
}
Run Code Online (Sandbox Code Playgroud)
另请注意,SSL证书已配置并正常工作,因此我认为它与端口,路径和转发的配置方式有关.我不知道重定向循环的来源.
Jer*_* S. 11
对于将来遇到这种情况的人,我能够通过force-ssl从捆绑的流星应用程序中删除包来解决问题.显然force-ssl和NGINX代理是冗余的,或者如果一起使用会导致太多的重定向.在我能够找到的材料中没有详细记录.
如果有一个配置支持将force-ssl与代理服务器一起用于某种目的,并且最好完全删除该软件包,请发布我想知道的内容.谢谢.
小智 5
只要你将X-Forward-Proto标头添加到你的Nginx配置中,我相信你可以保留force-ssl包.
例:
proxy_set_header X-Forward-Proto https;
Run Code Online (Sandbox Code Playgroud)
此外,请确保您具有X-Forward-For设置,尽管已经在您发布的示例中.