通过PM2在端口80上运行Node app [英] Running Node app via PM2 on port 80

查看:182
本文介绍了通过PM2在端口80上运行Node app的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我明确表示要在端口80上运行.-> app.listen(80);

I have an express that I want to run on port 80. --> app.listen(80);

我正在使用PM2来管理应用程序(重新启动,停止,监视等).我有一个部署Shell脚本,其最后一个命令为PM2 restart index.从控制台输出中,我没有看到任何错误,并且PM2报告它已成功完成了该命令.但是,当我到达my.ec2.ip.address:80时,该站点尚未启动.此外,如果在服务器项目目录中运行node index.js,则会得到一个Error: listen EACCES 0.0.0.0:80.这对我来说很有意义,因为端口80低于1024,因此是特权端口. sudo node index.js将允许启动工作.

I'm using PM2 to manage the app (restarting, stopping, monitoring, etc.) . I have a deployment shell script whose last command is PM2 restart index. From the console output, I see no errors and PM2 reports that it successfully completed the command. Yet when I got to my.ec2.ip.address:80 the site is not up. Furthermore, if I run node index.js in my server project directory, I get a Error: listen EACCES 0.0.0.0:80. This makes some sense to me as port 80 is below 1024 and therefore a privileged port. sudo node index.js will allow the launch to work.

我是unix,服务器,权限和部署的新手,因此,除了解决方案之外,对引起我问题的基本概念的解释将不胜感激.例如..以超级用户身份运行我的节点应用程序是否不好?以超级用户身份运行PM2(因此可能以..身份运行节点)是一种好习惯吗?命令sudo PM2 restart index导致sudo: pm2: command not found.如果PM2在我的路径中,为什么在运行sudo PM2时找不到PM2?

I'm a newbie to unix, servers, permissions, and deployment, so in addition to the solution, an explanation of the fundamental concepts contributing to my problem would be greatly appreciated. For instance.. is it bad to simply run my node app as super-user? Is it good practice to run PM2 (therefore possibly running node as..?) root/super-user? The command sudo PM2 restart index leads to sudo: pm2: command not found. Why is PM2 not found when running sudo PM2.. if PM2 is in my path?

但是,当最终使用PM2时,如何确保服务器在端口80上运行?找不到.

Ultimately though, when using PM2 how can I ensure that my server runs on port 80? not found.

推荐答案

不要使用端口80,在其他端口(例如8080)上运行,并使用此命令将80重定向到该端口

Dont use port 80, run on other port like 8080 and redirect 80 to that port with this command

  sudo iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080

这篇关于通过PM2在端口80上运行Node app的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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