JAVA和Nginx 教程大全

网站首页 > 精选教程 正文

Linux 部署 node环境,再玩个小项目

wys521 2024-10-10 12:33:58 精选教程 19 ℃ 0 评论

部署文件目录说明

/usr/local:用户级的程序目录,可以理解为C:/Progrem Files/。用户自己编译的软件默认会安装到这个目录下,像nginx,tomcat。

/usr/local/src:用户级的源码目录。像我们这里要部署的node项目文件夹就放这里面。

nodejs安装

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash

or Wget:

wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash

$ source ~/.nvm/nvm.sh

nvm install node

nvm use node

python安装(不报错跳过)

wget http://www.python.org/ftp/python/2.7.6/Python-2.7.6.tar.xz //下载

yum install xz-libs //解压工具如果没有就安装

xz -d Python-2.7.6.tar.xz //解压

tar -xvf Python-2.7.6.tar

cd Python-2.7.6

./configure --prefix=/usr/local

//我们需要自己安装Python 2.7.6。但是值得注意的是,我们必须不能破坏系统的环境。因为几个关键的实用应用程序依赖于Python 2.6.6。如果替换了系统的Python环境就会发生很多难以预见的错误,导致要重装系统

make && make altinstall

nginx安装

可以查看nginx安装

项目部署

node项目这里使用ftp客户端来上传

运行

一般用pm2或者forever等工具来管理,要不然关掉了服务就停了,这里我用的pm2

npm install pm2 -g

cd /usr/local/src/admin // admin是我建的node项目,放usr/local/src,上面提到的

NODE_ENV=production PORT=9203 pm2 start app.js --name xiaoyang // 这里根据你的配置写参数,我这里起了个9203的端口

然后我们看浏览器,这个时候已经可以访问了,带9203端口,http://xxx:9203

nginx配置

node项目已经可以运行了,现在我们来配下nginx,为啥要用nginx,因为nginx处理静态资源还是很强的

whereis nginx // 查看nginx安装目录

进入目录,添加xx.conf文件,写入

server {

listen 80;

server_name localhost;

location / {

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_set_header Host $http_host;

proxy_set_header X-Nginx-Proxy true;

proxy_set_header Connection "";

proxy_pass http://xxx:9203; #刚刚的node项目和配的端口,xxx是自己的IP

proxy_redirect default ;

}

}

重启nginx,因为这里配的是80,所以去掉端口号就可以运行了,http://xxx

ps:这里的前端页面用的是vue,下次讲

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表