Uninote
Uninote
用户根目录

url 重写

http://video.dajxyl.com/video_play.html?video_url=https://admin.bb.uninote.com.cn/oss?path=video/upload/202109/20210921_180347.mp4

模块前缀 & 前缀代理

  • 注意,每个模块都有自己特定的模块前缀,比如这里的 scmsapi,就代表了商城模块,此前缀用于代理时的分发判断,因此如果是直接访问接口而非通过代理访问,使用时需要移除此前缀,eg:
// 登录
export function login(params) {
  return post('/auth/login', params);
}

url rewrite 配置

  • 前缀匹配,则替换,循环所有的规则
    • 可以实现将 host 替换为任意地址:
    • 配置如下:

url 拼接

https://docs.dajxyl.com/book/1/2878#AF1D5248C8

http://video.dajxyl.com/video_play.html?video_url=https://admin.bb.uninote.com.cn/oss?path=video/upload/202109/20210921_184528.mp4

请求

直接请求,无代理

代理

http://video.dajxyl.com/video_play.html?video_url=https://admin.bb.uninote.com.cn/oss?path=video/upload/202109/20210921_185041.mp4

开发环境,devServe

http://video.dajxyl.com/video_play.html?video_url=https://admin.bb.uninote.com.cn/oss?path=video/upload/202109/20210921_190956.mp4

  • 容易超时

  • 有个坑:容易错误的代理,导致修改不起作用

在根目录创建 vue.config.my.js 文,本文件是git忽略的文件,仅在本地环境配置生效,参考配置如下:

module.exports = function (config) {
    delete config.devServer.proxy['/']; // 这里要取消 vue.config.js 中的配置
    config.devServer.proxy['/api'] = {
        ws: false, // proxy websockets
        target: 'https://dev.api.dajxyl.com',
        changeOrigin: true,
        pathRewrite: {
            "^/api": ""
        }
    };
    config.devServer.proxy['/staffapi'] = {
        ws: false, // proxy websockets
        target: 'https://dev.staffapi.dajxyl.com',
        changeOrigin: true,
        pathRewrite: {
            "^/staffapi": ""
        }
    };
    config.devServer.proxy['/cmsapi'] = {
        ws: false, // proxy websockets
        target: 'https://dev.admin.dajxyl.com',
        changeOrigin: true,
        pathRewrite: {
            "^/cmsapi": ""
        }
    };
    config.devServer.proxy['/scmsapi'] = {
        ws: false, // proxy websockets
        target: 'https://dev.s.dajxyl.com',
        changeOrigin: true,
        pathRewrite: {
            "^/scmsapi": ""
        }
    };
}

nginx 代理

开发环境:base + 跨域 + nginx 代理 -- 终极方案

http://video.dajxyl.com/video_play.html?video_url=https://admin.bb.uninote.com.cn/oss?path=video/upload/202109/20210921_191958.mp4

注意:这个方案有个问题,就是无法使用 cookie,导致 cms 登录后无法存储 PHPSESSID, 临时解决方案:手动登录后将 PHPSESSID 存入名为 cmsphpsid 的参数中

跨域 header 重复问题

https://github.com/openresty/headers-more-nginx-module

http://video.dajxyl.com/video_play.html?video_url=https://admin.bb.uninote.com.cn/oss?path=video/upload/202109/20210921_193010.mp4

http://powderproxy.dajxyl.com 参考配置:

server{
    listen 80;
    server_name powderproxy.dajxyl.com;
    access_log  logs/powderproxy.access.log;
    error_log   logs/powderproxy.error.log;

    more_set_headers 'Access-Control-Allow-Origin: *';
    more_set_headers 'Access-Control-Allow-Methods: GET, POST, OPTIONS';
    more_set_headers 'Access-Control-Allow-Headers: DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization,Powder-ReqIndex,Powder-TrackID,token';
    more_set_headers 'Access-Control-Allow-Credentials: true';
    if ($request_method = 'OPTIONS') {
        return 204;
    }

    location  /staffapi {
        rewrite /staffapi/(.*)$ /$1 break;
        proxy_pass https://dev.staffapi.dajxyl.com;
        proxy_set_header Host      $proxy_host;
        proxy_set_header X-Real-IP $remote_addr;
    }

    location /api {
        rewrite /api/(.*)$ /$1 break;
        proxy_pass https://dev.api.dajxyl.com;
        proxy_set_header Host      $proxy_host;
        proxy_set_header X-Real-IP $remote_addr;
    }

    location  /staffapia {
        rewrite /staffapi/(.*)$ /$1 break;
        proxy_pass https://dev.staffapi.dajxyl.com;
        proxy_set_header Host      $proxy_host;
        proxy_set_header X-Real-IP $remote_addr;
    }

    location  /cmsapi {
        rewrite /cmsapi/(.*)$ /$1 break;
        proxy_pass https://dev.admin.dajxyl.com;
        proxy_set_header Host      $proxy_host;
        proxy_set_header X-Real-IP $remote_addr;
    }

    location  /scmsapi {
        rewrite /scmsapi/(.*)$ /$1 break;
        proxy_pass https://dev.s.dajxyl.com;
        proxy_set_header Host      $proxy_host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}

powder-old

powder-test

点赞(0) 阅读(1) 举报
目录
标题