0
点赞
收藏
分享

微信扫一扫

Nginx上发布Angular解决路由问题

东林梁 2022-08-22 阅读 64

一、安装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/​​

 

 

作者:沐雪 文章均系作者原创或翻译,如有错误不妥之处,欢迎各位批评指正。本文版权归作者所有,如需转载恳请注明。
​​​ 为之网-热爱软件编程 http://www.weizhi.cc/​​

举报

相关推荐

0 条评论