您是否设法在Heroku上设置节点nginx代理设置? [英] Have you managed to make your node nginx proxy setup on Heroku work?

查看:371
本文介绍了您是否设法在Heroku上设置节点nginx代理设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



你能告诉我你是如何组织目录结构和文件的吗?你有没有设法在Heroku上设置Node + nginx代理设置?在做每个目录之前git push heroku master?你使用了哪个buildpack?每当我做git push heroku master时,我会收到消息推送被拒绝,没有检测到Cedar支持的应用程序。我已将nginx.conf.erb文件放在/ conf目录中。



谢谢。

解决方案

我在很多项目上使用过heroku上的Node.js + NGINX设置。
这样,您可以让nginx句柄提供静态文件,缓存,代理到其他服务器,以及代理到多个节点进程。



使用多buildpack buildpack( https://github.com/ddollar/heroku-buildpack-multi )。

它允许您指定一个指向多个buildpack的.buildpacks文件。
在我的.buildpacks文件中,我使用默认的Heroku Node buildpack和一个我重建的包含SSL支持的nginx buildpack的分支。

  https://github.com/theoephraim/nginx-buildpack.git 
https://github.com/heroku/heroku-buildpack-nodejs.git

nginx buildpack使用可引用ENV变量的nginx.conf.erb文件。您必须告诉它在名为PORT的环境变量中监听由heroku指定的端口。

  listen<%= ENV [PORT]%>; 

然后你的节点服务器启动你选择的任何端口,比如说5001,在你的nginx config,你可以设置代理传递给你的节点应用程序:

  location / {
proxy_pass http:// 127.0.0.1:5001;

$ / code>

注意 - 您的procfile需要使用特殊的start-nginx命令nginx构建包),然后调用通过它的任何其他内容。在我的情况下,我永远使用我的节点应用程序:

  web:bin / start-nginx ./node_modules/.bin/永远的app.js 

在您的主节点文件中,您必须在启动时创建一个文件成功向nginx构建包发出信号,表明它应该开始监听

  fs.openSync('/ tmp / app-initialized',' W'); 

有关如何在自述文件中使用nginx buildpack的完整说明@ https://github.com/theoephraim/nginx-buildpack


Have you managed to make your node + nginx proxy setup on Heroku work?

Could you, please, tell me how have your organized the directories structure and the files in each directory before doing "git push heroku master"? Which buildpack did you use?

I am getting the message "Push rejected, no Cedar-supported app detected" every time I do "git push heroku master". I have put a "nginx.conf.erb" file in a "/conf" directory.

Thank you.

解决方案

I have used a Node.js + NGINX setup on heroku for many projects. This way, you can have nginx handle serving static files, caching, proxying to other servers, and proxying to several node processes.

Use the multi-buildpack buildpack (https://github.com/ddollar/heroku-buildpack-multi).
It allows you to specify a .buildpacks file which refers to several buildpacks. In my .buildpacks file, I use the default Heroku Node buildpack, and a fork of an nginx buildpack that I rebuilt to include SSL support.

https://github.com/theoephraim/nginx-buildpack.git
https://github.com/heroku/heroku-buildpack-nodejs.git

The nginx buildpack uses a nginx.conf.erb file that can reference ENV vars. You must tell it to listen on the port specified by heroku in the environment variable called "PORT"

listen <%= ENV["PORT"] %>;

Then you have your node server start up on whatever port you choose, say 5001, and in your nginx config, you can set up a proxy pass to your node app:

location / {
  proxy_pass      http://127.0.0.1:5001;
}

Note - your procfile needs to use a special start-nginx command (part of the nginx buildpack) that then calls whatever else you pass it. In my case I use forever to run my node app:

web: bin/start-nginx ./node_modules/.bin/forever app.js

And within your main node file, you must create a file when it has started up successfully to signal to the nginx buildpack that it should begin listening

fs.openSync('/tmp/app-initialized', 'w');

There is a full explanation of how to use the nginx buildpack in the readme @ https://github.com/theoephraim/nginx-buildpack

这篇关于您是否设法在Heroku上设置节点nginx代理设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆