1、主站点方向代理test指向项目服务器
主站点反向代理配置
server {
listen 80;
server_name www.main.com;
#charset koi8-r;
#access_log logs/host.access.log main;
index index.html;
root ./html;
#反向代理test指向项目服务器
location /test {
#root html;
#index index.html index.htm;
proxy_set_header Host $host;
proxy_set_header X-Real-Ip $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
client_max_body_size 220m;
proxy_pass http://www.project:3000/test;
}
2、项目nginx将打包的vue打包
2.1)vue打包配置
vue.config.js
productionSourceMap: true,
#publicPath名称与主站点反向代理路径(/test) 一致。
publicPath: '/test/',
assetsDir: 'static',
2.2)项目nginx配置
server {
listen 3000 ;
server_name www.project.com;
#charset koi8-r;
#access_log logs/host.access.log main;
index index.html;
#dist上传的路径
root E://cszjz//jeecg-boot-master1//jeecg-boot-master//ant-design-vue-jeecg//dist;
location /test/ {
#虚拟路径
alias E://cszjz//jeecg-boot-master1//jeecg-boot-master//ant-design-vue-jeecg//dist//;
# 避免访问出现 404 错误,页面不能刷新问题
try_files $uri $uri/ @router;
index index.html;
}
#后端请求代理转发
location ^~ /jeecg-boot {
# 能从项目ip访问到 的内网IP 或内网域名
proxy_pass http://192.168.1.65:9090/jeecg-boot/;
proxy_set_header Host jeecg-boot-system;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
}
#图片缓存,缓存时长 1天
location ~ .*\.(gif|jpg|png|css|js|flv|ico|swf)?$
{
expires 1d;
}
location @router {
rewrite ^.*$ /index.html last;
}
vue打包文件列表
4、vue配置后端请求地址
#(项目做了jeecg-boo反向代理,项目在外网嫩访问)项目外网ip和端口端口或(门户做了jeecg-boot反向代理情况下门户的IP和端口与jeecg-boot
#http://www.project.com/jeecg-boot 或 http://www.portal.com/jeecg
VUE_APP_API_BASE_URL=http://192.168.1.65:3000/jeecg-boot