搭建 Nodejs 生产环境

1、node安装与配置node

一、环境:阿里云ubuntu16.04webpack

二、更新:sudo apt-get updatenginx

三、安装相关依赖文件:git

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

四、安装nvmgithub

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

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

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

nvm install 6.11.4

六、指定系统默认版本:npm

nvm use 6.11.4

nvm alias default 6.11.4

七、将npm源设置成淘宝源gulp

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

 监控文件数目:ubuntu

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

八、安装cnpm

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

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

npm install pm2 webpack gulp grunt-cli -g

 


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

一、若是有apache咱们移除下:

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

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

apt-get install nginx

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

upstream testweb{
    server 127.0.0.1:8080;
}
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 http://test.bradball.xin;
        proxy_redirect off;
        }
}

 四、返回到/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是否有错误
相关文章
相关标签/搜索