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

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

问题描述

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

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

请您告诉我,在执行git push heroku master"之前,您是如何组织目录结构和每个目录中的文件的?您使用的是哪个 buildpack?

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?

我每次执行git push heroku master"时都会收到消息推送被拒绝,未检测到雪松支持的应用程序".我已将nginx.conf.erb"文件放在/conf"目录中.

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.

谢谢.

推荐答案

我在 heroku 上为许多项目使用了 Node.js + NGINX 设置.通过这种方式,您可以让 nginx 处理静态文件的服务、缓存、代理到其他服务器以及代理到多个节点进程.

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.

使用 multi-buildpack buildpack (https://github.com/ddollar/heroku-buildpack-多).
它允许您指定一个引用多个构建包的 .buildpacks 文件.在我的 .buildpacks 文件中,我使用默认的 Heroku Node buildpack,以及我重建以包含 SSL 支持的 nginx buildpack 的一个分支.

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

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

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"] %>;

然后你让你的节点服务器在你选择的任何端口上启动,比如 5001,在你的 nginx 配置中,你可以设置一个到你的节点应用程序的代理传递:

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;
}

注意 - 您的 procfile 需要使用一个特殊的 start-nginx 命令(nginx buildpack 的一部分),然后调用您传递的任何其他命令.就我而言,我使用永远运行我的节点应用程序:

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

在你的主节点文件中,你必须在它成功启动后创建一个文件,以通知 nginx buildpack 它应该开始监听

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');

readme@https://github 中有关于如何使用 nginx buildpack 的完整说明.com/theoephraim/nginx-buildpack

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

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