简体   繁体   English

Heroku 上的 Nginx + Node.js

[英]Nginx + Node.js at Heroku

Do i still to configure nginx if I want to deploy my node.js application on Heroku?如果我想在 Heroku 上部署我的 node.js 应用程序,我还需要配置 nginx 吗? or Heroku already handle that part?或者 Heroku 已经处理了那部分?

If I do need to configure, what are the steps?如果我确实需要配置,步骤是什么? for those of you who have experienced deploying it on heroku, could you guide me.对于那些在 heroku 上部署过它的人,你能指导我吗? This will be my first time deploying something for real :)这将是我第一次真正部署一些东西:)

Thank you谢谢

Heroku handles the proxy between your app to port 80 (or SSL port when applicable) for you. Heroku 为您处理您的应用程序与端口 80(或适用的 SSL 端口)之间的代理。 But the port for your app is not fixed, it is potentially variable but always available as an Environment Variable PORT .但是您的应用程序的端口不是固定的,它可能是可变的,但始终可以作为环境变量PORT

So in your node.js app, you should listen to process.env.PORT instead of a fixed value.因此,在您的 node.js 应用程序中,您应该监听process.env.PORT而不是固定值。 Further, to make the app run both locally and on Heroku environment, you can do process.env.PORT || 3000此外,要使应用程序在本地和 Heroku 环境中运行,您可以执行process.env.PORT || 3000 process.env.PORT || 3000 assuming 3000 is your choice of the port number for local development purposes. process.env.PORT || 3000假设 3000 是您选择的用于本地开发目的的端口号。

See https://devcenter.heroku.com/articles/dynos#local-environment-variables for further details.有关更多详细信息,请参阅https://devcenter.heroku.com/articles/dynos#local-environment-variables

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM