简体   繁体   English

GCP计算引擎-无法在端口80上侦听?

[英]GCP Compute Engine - cannot listen on port 80?

I created a compute engine which has these network tags and firewall rules: 我创建了一个具有以下网络标记和防火墙规则的计算引擎: 在此处输入图片说明

在此处输入图片说明 So if I understand this correctly, the machine is allowed to listen on port 80 . 因此,如果我正确理解这一点, 则机器可以在端口80上侦听 I installed node and created a really simple http server just to see if I can reach the box via http. 我安装了node并创建了一个非常简单的http服务器,以查看是否可以通过http到达该框。 Logged in via ssh on cloud console. 在云控制台上通过ssh登录。 When I try to start it (eg npm start to run the server), it says: 当我尝试启动它(例如npm start来运行服务器)时,它说:

Error: listen EACCES: permission denied 0.0.0.0:80

Why? 为什么? How to resolve? 怎么解决?

I read somewhere that low port #s are usually restricted to root user, so I tried sudo it says sudo: npm: command not found and similar for sudo node. 我在某个地方读到低端口号通常仅限于root用户,因此我尝试了sudo它说sudo: npm: command找不到sudo: npm: command ,与sudo节点类似。

Also why is that when you create a server using scripts like these , the article says they are executed as root? 同样为什么在使用此类脚本创建服务器时,文章说它们是作为root执行的? How does that happen and why am I not executing as root when I'm the one who booted up the machine and logged in as myself? 这是怎么发生的?当我启动计算机并以自己的身份登录时,为什么不以root用户身份执行? Yes, my understanding of linux perms is very newbie. 是的,我对linux perms的理解非常新手。

Thanks... 谢谢...

In order to use TCP ports lower than 1024 you node server must run with root privileges. 为了使用低于1024的TCP端口,您的节点服务器必须以root特权运行。 TCP ports 1024 and higher do not require privilege. TCP端口1024及更高端口不需要特权。

When you login to a Google Cloud Compute Engine instance, you are loggin in as a normal user. 登录到Google Cloud Compute Engine实例后,您将以normal用户身份登录。 You do not have root privilege. 您没有root特权。 To grant root privilege to a command, prefix it with sudo . 要为命令授予root特权,请在命令前添加sudo Example: sudo mkdir /directoryname . 例如: sudo mkdir /directoryname

I do NOT recommend running node servers with root privilege. 建议以root特权运行节点服务器。 This opens a possibly serious security hole in your system. 这在您的系统中可能会造成严重的安全漏洞。 Search the Internet on this topic before deciding. 在决定之前,请先搜索有关此主题的Internet。

Your choices are: 您的选择是:

  1. Select a port above 1023. Common port numbers: 8000, 8080, 5000. 选择1023以上的端口。公用端口号:8000、8080、5000。
  2. Start the node server with root privileges: sudo node hello.js 使用root特权启动节点服务器: sudo node hello.js

In regards to npm not being found. 关于npm找不到。 You will need to modify the environment's PATH variable to include the location of where you installed your node toolset for the user root . 您将需要修改环境的PATH变量,以包括为root用户安装节点工具集的位置。

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

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