安装Node
安装nvm
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
安装node
nvm install v10.15.1
指定系统使用新的Node
nvm alias default v10.15.1
指定淘宝源
npm --registry=https://registry.npm.taobao.org install -g npm
查看系统当前的max_user_watches值
cat /proc/sys/fs/inotify/max_user_watches
增加系统当前的max_user_watches值
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
安装常用node软件
npm i pm2 webpack gulp grunt-cli -g
测试服务
//app.js
const http = require('http')
http.createServer(function (req,res) {
res.writeHead(200,{'Content-Type':'text/plain'})
res.end('hello world')
}).listen(8080)
启动服务
node app.js
pm2使用
服务持久化
pm2 start app.js
pm2基础使用
启用一个应用: pm2 start app.js
停止:pm2 stop app_name|app_id
删除:pm2 delete app_name|app_id
重启:pm2 restart app_name|app_id
停止所有:pm2 stop all
查看所有的进程:pm2 list
查看所有的进程状态:pm2 status
查看某一个进程的信息:pm2 describe app_name|app_id
查看当前使用pm2管理的应用: pm2 show app_name
打印日志:pm2 logs
删除apache节省空间
updata-rc.d -f apache2 remove
apt-get remove apache2
update-rc.d 是在 Debian 或 Ubuntu 內用來管理 /etc/init.d blog.wu-boy.com/2017/04/upd…
nginx反向代理
安装ngnix
apt-get update
apt-get nginx
nginx -v
新增配置文件
cd /etc/nginx/conf.d/
vi ljx-com-8080.conf
配置ljx-com-8080.conf文件
upstream ljx {
server 127.0.0.1:8080;
}
server {
listen 80;
server_name 192.168.1.109; //注意这里填写的是你自己的服务器IP
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://ljx;
proxy_redirect off;
}
}
参考资料:segmentfault.com/a/119000000…
测试配置文件是否正确
nginx -t
重启nginx
nginx -s reload
直接访问192.168.1.109:80/192.168.1.109,此时访问80端口为被自动代理到8080端口