你的位置:首页 > 软件开发 > Java > 搭建 Nodejs 生产环境

搭建 Nodejs 生产环境

发布时间:2017-10-18 15:00:10
一、node安装与配置1、环境:阿里云ubuntu16.042、更新:sudo apt-get update3、安装相关依赖文件:sudo apt-get install vim openssl build-essential libssl-dev wget curl git4、 ...

一、node安装与配置

1、环境:阿里云ubuntu16.04

2、更新:sudo apt-get update

3、安装相关依赖文件:

sudo apt-get install vim openssl build-essential libssl-dev wget curl git

4、安装nvm

https://github.com/creationix/nvm 找到,并使用

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.5/install.sh | bash
下载完成后source ~/.bashrc完成后重新打开一个终端

搭建 Nodejs 生产环境

 5、使用nvm 安装 nodejs稳定版本(截至20171015)

nvm install 6.11.4

搭建 Nodejs 生产环境

搭建 Nodejs 生产环境

6、指定系统默认版本:

nvm use 6.11.4

搭建 Nodejs 生产环境

nvm alias default 6.11.4

搭建 Nodejs 生产环境

7、将npm源设置成淘宝源

npm --registry=https://registry.npm.taobao.org install -g npm

搭建 Nodejs 生产环境

 监控文件数目:

echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

8、安装cnpm

npm --registry=https://registry.npm.taobao.org install -g cnpm

9、安装常用全局工具包(按需选择性安装):

npm install pm2 webpack gulp grunt-cli -g

 


 二、配置 Nginx 实现反向代理;

1、如果有apache我们移除下:

update-rc.d -f apache2/apache remove
apt-get remove apache2/apache

2、直接使用apt-get安装Nginx

apt-get install nginx

搭建 Nodejs 生产环境

3、进入/etc/nginx/conf.d,新建一个配置文件:testweb_8090.conf

upstream testweb{
    server 127.0.0.1:8090;
}
server{
    listen 80;
    server_name 120.78.147.101;

    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;

        proxy_set_header Host $http_host;
        proxy_set_header X-Nginx-Proxy true;

        proxy_pass       proxy_redirect off;
        }
}

 4、返回到/etc/nginx .备份下nginx.conf

cp nginx.conf nginx.conf.bak

然后进入 vim nginx.conf

参看include /etc/nginx/conf.d/*.conf;include /etc/nginx/sites-enabled/*;是否打开,没打开就去掉注释
nginx -t //测试nginx是否有错误

 nginx开启、关闭、以及重启:

service nginx start //开启
nginx -s reload  //重启

service nignx start //关闭

service nginx status //查看状态

  

原标题:搭建 Nodejs 生产环境

关键词:JS

JS
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。