1.将vue项目打包放到指定位置,比如/data下

2.安装nginx

centos7在线安装比较方面,可以直接使用命令:yum install nginx安装,具体步骤如下:

2.1.修改yum源

查看源地址:http://nginx.org/en/linux_packages.html#RHEL-CentOS

2.2.安装yum-utils

yum install yum-utils

2.3修改源地址

vi /etc/yum.repos.d/nginx.repo

2.4切换为主线分支

yum-config-manager --enable nginx-mainline

2.5安装

yum install nginx

3.配置nginx

nginx在线安装之后的默认路径为/etc/nginx,配置文件在/conf.d文件夹,修改默认配置文件即可,简易版完整配置代码如下:

server {
    #应用端口
    listen       8888;
    server_name  localhost;

    #用户及前端路径
    root    /data/demo-vue/;
    #默认访问文件
    index  index.html;  

    location / {
       try_files $uri $uri/ /index.html;
    }

    #后端接口地址
    location ^~ /gateway/ {
       proxy_pass http://127.0.0.1:8080/demo/;
       proxy_set_header Host $host;
       proxy_set_header X-Real-IP $Remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

       #proxy_buffering off;
    }
}

4.nginx常用命令

启动

systemctl start nginx

停止

systemctl stop nginx

重启

systemctl restart nginx

重载

systemctl reload nginx

查看状态

systemctl status nginx

 

Logo

前往低代码交流专区

更多推荐