前端请求/authapi/auth/permissions 实际发给后端 /api/auth/permissions 本地和线上配置

VITE_GLOB_API_URL_PREFIX = /authapi

VITE_PROXY = [["/api","http://192.168.50.2:6066"],["/tms","http://192.168.50.5:6088"],["/authapi","http://im.auth.com"],["/s3-pdf","https://anteater-image.s3.us-east-2.amazonaws.com"]]

vite.config.ts 文件
复制代码
import { defineConfig } from 'vite'

export default defineConfig({
  server: {
    proxy: {
      '/authapi': {
        target: 'http://im.auth.com',
        changeOrigin: true,
        rewrite: (path) =>
          path.replace(/^\/authapi/, '/api') // 修改这里
      },
       '/tms': {
        target: 'http://192.168.50.5:6088',
        changeOrigin: true,
        rewrite: (path) =>
          path.replace(/^\/tms/, '/api') // 修改这里
      }
    }
  }
})
线上(Nginx)配置(必须对称
复制代码
location /authapi/ {
    proxy_pass http://im.auth.com/api/;  # ✅ 注意 /api/

    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Authorization $http_authorization;
}
location /tms/ {
    proxy_pass http://192.168.50.5:6088/api/;  # ✅ 注意 /api/

    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Authorization $http_authorization;
}
本地靠 Vite 的 rewrite,线上靠 Nginx 的 proxy_pass /api/。
相关推荐
可乐泡枸杞2 小时前
《我用AI,一个月做出学了吗APP》
前端·人工智能·后端
韭菜炒大葱2 小时前
详解:useMemo 和useCallback
前端·react.js·面试
huipeng9262 小时前
基于SpringCloud的博客系统
java·运维·后端·spring·spring cloud·微服务
倔强的石头1062 小时前
【Linux 指南】文件系统系列(三):Ext系统核心实现 —— 从块组到 inode 与数据块映射全解析
大数据·linux·运维
ZC跨境爬虫2 小时前
跟着 MDN 学 HTML day_62:(HTML调试与常见错误修复指南)
java·前端·javascript·ui·html·媒体
Hunter_pcx3 小时前
ubuntu:内存假泄漏
linux·运维·服务器·开发语言·c++·人工智能·ubuntu
赵成ccc3 小时前
【无标题】
linux·nginx
REDcker3 小时前
Playwright详解 Web自动化与E2E测试 架构原理与实战入门
前端·架构·自动化
用户86022504674723 小时前
从入门到进阶的 React Native 实战指南
android·前端