📄 nginx 部署微服务前端
内部资料,请扫码登录
pigcloud
# 安装 NGINX
vim /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
sudo yum-config-manager --enable nginx-mainline
sudo yum install nginx
# 配置 NGINX
vim /etc/nginx/conf.d/pigx-ui.conf
server {
listen 80;
server_name localhost;
gzip on;
gzip_static on; # 需要http_gzip_static_module 模块
gzip_min_length 1k;
gzip_comp_level 4;
gzip_proxied any;
gzip_types text/plain text/xml text/css;
gzip_vary on;
gzip_http_version 1.0; #兼容多层nginx 反代
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
# 前端打包好的dist目录文件
root /data/pigx-ui/;
# 若新增后端路由前缀注意在此处添加(|新增)
location ~* ^/(code|auth|admin|monitor|gen|job|tx|act|mp|pay|jimu|aj)
proxy_pass http://pigx-gateway:9999/; #注意/后缀
proxy_connect_timeout 60s;
proxy_read_timeout 120s;
proxy_send_timeout 120s;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto http;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
}
# 避免端点安全问题
if ($request_uri ~ "/actuator"){
return 403;
}
}
# 前端打包
npm run build
复制 dist
文件下的资源 上传到 NGINX 配置文件指定的文件目录