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

穿精又带淫゛_ 提交于 2019-12-03 09:51:39

问题


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.


回答1:


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




回答2:


This article contains instructions on setting up nginx as a proxy on Heroku, in conjunction with OpenResty, Lua, and LuaRocks. node.js isn't mentioned. It uses this buildpack. Haven't tried it myself but seems someone has got it working.




回答3:


On Heroku, this setup is used in production by me successfully once the buildpack is installed:

upstream node_entry {
    server unix:/tmp/nginx.socket fail_timeout=0;
}
server {
    listen  <%= ENV['PORT'] %>;
    server_name localhost;
    keepalive_timeout 5;
    location / {
        [other settings…]
        proxy_pass http://node_entry;
    }
}

Then, in your app.js file you can connect with:

Server.listen(‘/tmp/nginx.socket’);


来源:https://stackoverflow.com/questions/17745308/have-you-managed-to-make-your-node-nginx-proxy-setup-on-heroku-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!