美文网首页
部署相关--nginx、pm2

部署相关--nginx、pm2

作者: 每天都睡不醒 | 来源:发表于2018-09-21 02:59 被阅读0次

ps: 阿里云ECS空置了半年,域名也扔了俩月了至今没有备案!深感浪费!!!今天终于开始域名备案流程,顺便倒腾了下ECS,之前有安装Ubuntu、node环境、Git等,于是乎,搞定备案之后学习了下Nginx的使用~~~

一、Nginx 安装

sudo apt-get update  // 更新软件包
sudo apt-get install nginx  // 安装Nginx

二、Nginx 完全卸载

1.删除nginx,–purge包括配置文件

sudo apt-get --purge remove nginx

2.自动移除全部不使用的软件包

sudo apt-get autoremove

3.罗列出与nginx相关的软件

dpkg --get-selections|grep nginx

执行结果:

stephen@stephen-OptiPlex-390:~$ dpkg --get-selections|grep nginx

nginx                       install
nginx-common                install
nginx-core                  install

4.删除3.查询出与nginx有关的软件

sudo apt-get --purge remove nginx
sudo apt-get --purge remove nginx-common
sudo apt-get --purge remove nginx-core

这样就可以完全卸载掉nginx包括配置文件
5.查看nginx正在运行的进程,如果有就kill掉

ps -ef |grep nginx

6.kill nginx进程

sudo kill  -9  7875 7876 7877 7879

7.全局查找与nginx相关的文件

sudo  find  /  -name  nginx*

8.依次删除7列出的所有文件

sudo rm -rf file

三、Nginx 配置静态页面

1、进入nginx目录下 sites-enabled 目录,找到默认配置文件 default.conf


/etc/nginx/

2、使用vim编辑器修改配置文件为

server {
        listen 80 default_server;
        server_name _;
        location / {
                root   /var/www/demo;     //静态.html文件存放目录
        }
}

3、 ubuntu 重启Nginx

systemctl restart nginx
启动nginx服务
systemctl start nginx.service

设置开机自启动
systemctl enable nginx.service

停止开机自启动
systemctl disable nginx.service

查看服务当前状态
systemctl status nginx.service

重新启动服务
systemctl restart nginx.service

查看所有已启动的服务
systemctl list-units --type=service

四、Nginx 配置node服务

1、使用vim编辑器修改 sites-enabled/ default.conf 配置文件为

server {
        listen 80 default_server;
        server_name _;
        location / {
                proxy_pass       http://127.0.0.1:3000;
                proxy_set_header Host      $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
}

五、安装pm2管理node进程

ps:

  1. 什么是pm2?
  2. express
npm install pm2 -g  // 安装pm2
pm2 start ./bin/www --watch   //启动node服务

ps: pm2 list
    pm2 stop     <app_name|id|'all'|json_conf>
    pm2 restart  <app_name|id|'all'|json_conf>
    pm2 delete   <app_name|id|'all'|json_conf>

相关文章

网友评论

      本文标题:部署相关--nginx、pm2

      本文链接:https://www.haomeiwen.com/subject/smionftx.html