您是否设法在Heroku上设置节点nginx代理设置?

编程入门 行业动态 更新时间:2024-10-07 12:19:21
本文介绍了您是否设法在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( github/ddollar/heroku-buildpack-multi )。 它允许您指定一个指向多个buildpack的.buildpacks文件。 在我的.buildpacks文件中,我使用默认的Heroku Node buildpack和一个我重建的包含SSL支持的nginx buildpack的分支。

github/theoephraim/nginx-buildpack.git github/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的完整说明@ github/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 (github/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.

github/theoephraim/nginx-buildpack.git github/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 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 @ github/theoephraim/nginx-buildpack

更多推荐

您是否设法在Heroku上设置节点nginx代理设置?

本文发布于:2023-11-23 06:49:15,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:节点   您是否   Heroku   nginx

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!