CentOS 部署前端项目,Nginx反向代理,搭建node服务

1.nginx配置

1.1. 安装

# 1. 安装GCC编译器
$ yum install -y gcc

#2. 安装G++编译器
$ yum install -y gcc-c++

# 3. 安装PCRE库
$ yum install -y pcre pcre-devel

# 4. 安装zlib库
$ yum install -y zlib zlib-devel

下载与解压缩Nginx

$ mkdir soft
$ cd soft/
$ wget http://nginx.org/download/nginx-1.18.0.tar.gz
$ tar -zxvf nginx-1.18.0.tar.gz

想让vim编辑Nginx的配置文件高亮显示,执行以下命令:

$ cp -r contrib/vim/* /usr/share/vim/vimfiles/

安装Nginx

$ cd nginx-1.18.0
$ ./configure
$ make
$ make install

 Nginx安装后默认的目录 :

Nginx默认安装目录/usr/local/nginx/
二进制文件路径/usr/local/nginx/sbin/nginx
配置文件路径/user/local/nginx/conf/nginx.conf

 1.2.安装成功后继续进行操作

查看nginx位置

# 查找 nginx 所在位置
$ whereis nginx

$ cd /usr/local/nginx

# 进入启动文件夹
$ cd sbin

# 启动nginx
$ ./nginx

nginx 常用命令

# 1. 启动nginx
$ cd /usr/local/nginx/sbin

./nginx

# 2. 停止nginx(直接全部停止)
$ ./nginx -s stop

# 3. 停止nginx (正常停止,慢慢关闭所有进程)
$ ./nginx -s quit

# 4. 更改配置文件后,重新加载(常用)
$ ./nginx -s reload  

# 5. 查看 nginx 进程
$ ps axu|grep nginx

# 6. 查看nginx 配置文件
$ cd /usr/local/nginx/conf

# nginx 配置文件
$ vim nginx.conf 

1.3.配置代理服务

到对应路径 (  /user/local/nginx/conf/nginx.conf  ),执行以下代码,

$ vim nginx.conf

配置如下: 

server {
        listen       80;
        listen       [::]:80;
        server_name  _;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
          root /root/jch/www/mmt/dist;
          index index.html;
          try_files $uri $uri/ /index.html;
        }

        location /api {
          proxy_pass http://xx.xxx.xxx.xxx;
        }

        location ^~/beeapi/ {
          rewrite ^/beeapi/(.*)$ /$1 break;
          proxy_pass http://localhost:3000;
        }

        location /bee {
          alias /test/bee/dist/;
          index index.html;
        }

        error_page 404 /404.html;
        location = /404.html {
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }
    }

2.安装CentOS nodejs

# 下载 安装 node 和 npm 
$ sudo yum install -y nodejs nodejs-legacy npm


# npm 下载慢可以更换淘宝镜像
$ sudo npm config set registry https://registry.npm.taobao.org

# 全局安装
$ sudo npm install -g n
$ sudo n stable

# 查看版本,检测安装是否成功
$ npm -v
$ node -v
# 然后到对应的路径就可以启动nodel
node app.js

node 需要后台运行,否则关闭窗口node就会关闭

安装 forever,保护进程

# 安装 forever
$ npm install -g forever

# forever 重新启动
$ forever start app.js

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值