栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

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

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

 

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/825915.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号