搭建 Nodejs 生产环境

一、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
完成后重新打开一个终端

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

nvm install 6.11.4

6、指定系统默认版本:

nvm use 6.11.4

nvm alias default 6.11.4

7、将npm源设置成淘宝源

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

 监控文件数目:

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

3、进入/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;
        }
}

 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是否有错误

转载于:https://www.cnblogs.com/xz1024/p/7685578.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值