Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to deploy nodejs in Centos

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

Today, the editor will share with you the relevant knowledge points about how to deploy nodejs in Centos. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article.

Install node and npm

Download the compiled node package from the official website:

Wget https://nodejs.org/dist/v6.10.2/node-v6.10.2-linux-x86.tar.xzxz-d node-v6.10.2-linux-x86.tar.xztar-xf node-v6.10.2-linux-x86.tar

Unzip it to get the node-v6.10.2-linux-x86 folder, which contains a bin directory that contains the node and npm we need.

It should be noted here that npm is linked to.. / lib/node_modules/npm/bin/npm-cli.js and cannot be copied directly to / usr/bin/, otherwise there will be errors, which can be seen using ll.

-rwxrwxr-x 1500 28746408 apr 4 05:04 nodelrwxrwxrwx 1500 38 may 1 08:03 npm- >.. / lib/node_modules/npm/bin/npm-cli.js

Configure environment variables

Edit the / etc/profile file:

Vi / etc/profile

Increase the path:

Path=$path:/home/node-v6.10.2-linux-x86/binexport pathsource / etc/profile

Create a new nodejs project

My own code will not make a fool of myself. Here, I will take a demo on the Internet to see the effect. Demo

Install git:

Yum install git

Ok, pull down the demo code on the server, npm install, and then use pm2 to run the program.

Npm install pm2-gpm2 start start.js-n demo

Type ip:8080 and you can see hello world! Yes!

Domain name bound to ip

Remember that there is a free domain name, just try to bind the domain name.

Fill in the ip address of the server in the a record of the domain name and wait for it to take effect.

Visit

Then through the domain name direct access, found that can not access our program, because the default access port is 80, and we listen to the port is 8080. Here you can pass:

Nginx reverse proxy

Iptables Port Forwardin

For simplicity, it is forwarded directly using the iptables port.

Iptables-t nat-a prerouting-p tcp-- dport 80-j redirect-- to-port 8080service iptables save / / Save the rules above are all the contents of the article "how to deploy nodejs in Centos". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report