vben: 把编译后的项目部署到线上

一,新加nginx站点:

说明:Vben Admin 默认使用前端路由(常见为 History 模式),直接刷新子路径会出现 404,因此 Nginx 必须配置 try_files;

server {
    listen 80;
    server_name your-frontend-domain.com; # 替换为你的前端访问域名或服务器 IP

    root /data/www/gyweb;
    index index.html;

    # 开启 gzip 压缩,提升加载速度
    gzip on;
    gzip_types text/plain text/css application/json application/javascript text/xml application/xml;

    # 前端 SPA 路由回退
    location / {
        try_files $uri $uri/ /index.html;
    }

    # 可选:若将 .env.production 中的 VITE_GLOB_API_URL 设为 /api,可通过 Nginx 反代到后端,避免跨域
    # location /api/ {
    #     proxy_pass http://gyweb.test.net/;
    #     proxy_set_header Host $host;
    #     proxy_set_header X-Real-IP $remote_addr;
    #     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    # }
}

二,重启nginx服务:

# systemctl reload openresty.service 

 

posted @ 2026-11-19 22:38  刘宏缔的架构森林  阅读(4)  评论(0)    收藏  举报