简体   繁体   English

如何在不使用gcloud上的deploy.sh文件的情况下为node.js应用程序打开端口80?

[英]How to open port 80 for a node.js application without deploy.sh file on gcloud?

I have a node application which runs fine if I manually putty into the gcloud computeVM and run it. 我有一个节点应用程序,如果我手动将腻子插入gcloud computeVM并运行它,则该应用程序运行良好。

Here are the complications (all realted to unix) : 这是复杂性(所有情况都适用于Unix):

1.) I have a domain name. 1.)我有一个域名。 So I added the dns zone record to point to the above VM. 因此,我添加了dns区域记录以指向上述VM。

2.) For the compute VM to respond, there should be process listening on 80 2.)为了使计算VM响应,应在80上侦听进程

3.) If we follow the https://cloud.google.com/nodejs/getting-started/run-on-compute-engine#download_app , it specifies to run the app on 8080. 3.)如果我们遵循https://cloud.google.com/nodejs/getting-started/run-on-compute-engine#download_app ,则它指定在8080上运行该应用程序。

4.) For ports < 1024, it requires root privileges to open up ports. 4.)对于<1024的端口,需要root特权才能打开端口。

5.) So from npm start, I changed the start up script to use "sudo npm start" 5.)因此从npm开始,我将启动脚本更改为使用“ sudo npm start”

6.) Then it gave the following error : my-app-instance supervisord: nodeapp sudo: no tty present and no askpass program specified 6.)然后给出以下错误:my-app-instancesupervisored:nodeapp sudo:不存在tty且未指定askpass程序

7.) If I have to "sudo visudo" everytime and add the "username ALL = NOPASSWD:" everytime I restart the instance after deployment , its something which I would least prefer. 7.)如果我每次都要“ sudo visudo”并在部署后每次重新启动实例时都添加“ username ALL = NOPASSWD:”,那是我最不希望的。

I have included the relevant portion of the stratup-script for more info : 我已经包含了stratup-script的相关部分以获取更多信息:

# Install app dependencies
cd /myrepo/opt/app/servers
sudo npm install

# Create a nodeapp user. The application will run as this user.
useradd -m -d /home/nodeapp nodeapp
chown -R nodeapp:nodeapp /myrepo/opt/app/servers

# Configure supervisor to run the node app.
cat >/etc/supervisor/conf.d/node-app.conf << EOF
[program:nodeapp]
directory=/myrepo/opt/app/servers
command=sudo npm start
autostart=true
autorestart=true
user=nodeapp
environment=HOME="/home/nodeapp",USER="nodeapp",NODE_ENV="production"
stdout_logfile=syslog
stderr_logfile=syslog
EOF

A.) My requirement is simple : My google domain points to the above compute VM now. A.)我的要求很简单:我的Google域现在指向上述计算VM。 whenever the user types www.domainname.com, it should take him to the website without any port numbers in the url. 每当用户键入www.domainname.com时,都应将其带到网站中,而网址中没有任何端口号。 How to open port 80 with a simple modification of start-up script(preferred) ? 如何通过简单修改启动脚本(首选)打开端口80?

B.) And also if I have to go with deploy.sh specified in the tutorial, will it get executed automatically ? B.)而且,如果我必须使用教程中指定的deploy.sh,它将自动执行吗? Or if I have to execute it automatically , whats the procedure. 或者,如果我必须自动执行它,该怎么办。

Note : I am not unix expert. 注意:我不是unix专家。 Any help would be appreciated. 任何帮助,将不胜感激。

Look into using a reverse proxy . 研究使用反向代理 This allows you to run your app without root privileges on a port like 8080, and have a privileged HTTP server (like Apache or Nginx) running on port 80 and proxying traffic to your app. 这样,您就可以在没有端口特权的情况下(例如8080)运行应用程序,并在端口80上运行特权HTTP服务器(例如Apache或Nginx),并将流量代理到您的应用程序。 This is common practice, and much more secure than running your app with root privileges. 这是常见的做法,比使用root特权运行您的应用程序安全得多。

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

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