Nginx上发布Angular解决路由问题

一、安装Nginx服务器
实验的机器 CentOS7.9
yum install epel-release
yum -y install nginx 安装

 

修改nginx的端口,默认80,改为9090:
vi /etc/nginx/nginx.conf
    server {
        listen       9090;
        listen       [::]:9090;
        server_name  _;
        root         /usr/share/nginx/html/dist/web;
        try_files $uri $uri/ /index.html;

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

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

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }
    }
其中:
try_files $uri $uri/ /index.html;

这句话是解决Angular路由问题。

 

 
还需要关闭selinux,将SELINUX=disabled
 
setenforce 0

先临时关闭.。

vi /etc/selinux/config 编辑文件,永久关闭
SELINUX=disabled
启动Nginx
systemctl enable nginx    设置开机启动
systemctl start nginx    启动
systemctl stop nginx    停止
systemctl restart nginx    重启

 

二、Angular部署

1、构建

npm install
npm run build

2、将dist拷贝到Nginx配置的静态地址。

 3、打开网址即可

http://192.168.66.110:9090/

 

 

 

 

 

 

 
posted @ 2021-11-17 12:33  沐雪架构师  阅读(238)  评论(0编辑  收藏  举报