阿里云服务器安装nodejs环境

来源:互联网 发布:centos pcre 下载 编辑:程序博客网 时间:2024/05/18 13:05

阿里云服务器上安装nodejs环境

  • 更新 Ubuntu
sudo apt-get updatesudo apt-get upgrade
  • 安装git
sudo apt-get install git
  • 安装nvm(用来管理node的版本)
    在github上面能找到安装的命令我们这里采用wget来安装
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.6/install.sh | bash
  • 安装node
    这里记得安装nvm以后重新打开一个窗口,执行后面的命令。例如我们这里需要安装node v8.9.1,并且指定默认版本为8.9.1
nvm install v8.9.1nvm use v8.9.1nvm alias default v8.9.1
  • 指定npm为淘宝的镜像源
npm --registry=https://registry.npm.taobao.org install -g npm

如果网络不好,使用npm下载不下来可以使用cnpm来进行下载

npm --registry=https://registry.npm.taobao.org install -g cnpm
  • 增加系统文件最大数量(以防万一)
 echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
  • 安装pm2(管理控制node进程的库)
npm install pm2 -g安装完成之后pm2 start app.js就可以让这个服务一直运行
  • 安装nginx
sudo apt-get install nginx然后进入到nginx目录下conf.dcd /etc/nginx/conf.d新建一个配置文件.conf内容为下面upstream huasheng{    server 127.0.0.1:8081;}server {    listen 80;    server_name 106.14.144.165;    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://huasheng;        proxy_redirect off;    }}然后测试一下sudo nginx -tnginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful出现上面打印说明nginx配置成功然后修改/etc/nginx/nginx.conf文件将server_tokens off;这个注释去掉,给前端页面的应答里面就不会带nginx对应的版本然后重启一下nginxsudo nginx -s reload然后就可以不带端口号访问到你的nodejs应用了

如果还不不能访问到,有可能是阿里云服务器上防火墙没有配置入方向80端口流量放行,一般配置一下就好了
这里写图片描述

  • mongodb搭建
    先下载好mongodb,下载教程
    mongodb
    下载完以后
启动mongodb服务sudo service mongod start然后查看log日志看是否启动成功cat /var/log/mongodb/mongod.log出现下面log说明启动成功2017-11-26T20:58:42.601+0800 I NETWORK  [thread1] waiting for connections on port 27017
原创粉丝点击