只看解决方法: 点击定位

项目ISSUE方法

  • 1.0之前: 通过修改容器网关openresty、nginx等实现
  • 1.0之后: 新建文件夹 cert, gateway-controller会定时检测证书信息(俺的cert文件夹挂载不进去啊,
    检查了编排文件与laf/packages/gateway-controller/src/support/apisix-gateway-init.ts 文件输出成功后都没反应)

也参考了下面的ISSUE

既然方法都没用, 就自己折腾一个方法。

尝试引入代理解决

实在折腾不了laf自身https, 我开始琢磨熟悉的nginx反向代理。中途碰了点坑记录一下。

尝试两个域名

  • A域名: nginx代理给用户https使用
  • B域名: 给Laf使用
  • 问题: 一次请求后变成用户用B域名通讯
  • 总结: 白给, 我不该这么想当然。
一次请求后变成用户用B域名通讯
一次请求后变成用户用B域名通讯

尝试一个域名

  • A域名: nginx代理给用户https使用, 并且与Laf通讯(Laf是8000端口不冲突)
  • 问题: Laf会携带.env的请求方式与端口号, 导致有些请求变成httpnginx拦截, 部分功能不可用
  • 总结: 多巧妙的解决方式, 可惜有内鬼。
部分功能不可用
部分功能不可用

完善一个域名

  • 总结: 纵观Laf模块功能, 把内鬼干掉, 还好内鬼只有一个文件
很奈斯
很奈斯

解决方法

步骤如下:

  1. 配置nginx
  2. 修改server容器的返回值

配置nginx

准备一个nginx, 服务器上的, docker上的都可以。

新建一个和Laf域名一致的网站, 注意Laf用到的域名有四种, 所以四种都要在你的域名列表里, 举例给你参考:

  1. 控制台域名: laf.thatcoder.cn
  2. 容器通配域名: *.laf.thatcoder.cn
  3. OSS域名: oss.laf.thatcoder.cn
  4. OSS通配域名: *.oss.laf.thatcoder.cn

其中 oss.laf.thatcoder.cn*.laf.thatcoder.cn 重叠, 所以需要 1、2、4 三个域名的解析与证书
所以上面的域名都代理在这个nginx的网站上, 并且需要1、2、4组合证书来开启SSL

开启SSL后配置反向代理, 配置文件如下:

反向代理
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
location ^~ / {
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 REMOTE-HOST $remote_addr;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_http_version 1.1;
proxy_cache_bypass $http_upgrade;

# 处理OSS通配 https://*.oss.laf.thatcoder.cn
if ($host ~* ^(.*?)\.oss\.laf\.thatcoder\.cn$) {
proxy_pass http://$1.oss.laf.thatcoder.cn:9000/;
}

# 捕获容器通配 https://*.laf.thatcoder.cn
if ($host ~* ^(.*?)\.laf\.thatcoder\.cn$) {
set $subdomain $1;
}

# 处理容器通配
if ($subdomain) {
proxy_pass http://$subdomain.laf.thatcoder.cn:8000/;
}

# 默认发送给主控制台
proxy_pass http://laf.thatcoder.cn:8000/;

add_header X-Cache $upstream_cache_status;

# 设置Nginx缓存
set $static_filequKUAdsO 0;
if ($uri ~* "\.(gif|png|jpg|css|js|woff|woff2)$") {
set $static_filequKUAdsO 1;
expires 1m;
}
if ($static_filequKUAdsO = 0) {
add_header Cache-Control no-cache;
}
}

修改server容器

进入容器 lafyun/system-server 找到 /app/dist/handler/application/get.js
修改文件最后的数据返回异步方法handleGetApplicationByAppid(), 将整个方法替换为

替换方法
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
async function handleGetApplicationByAppid(req, res) {
var _a;
const uid = (_a = req['auth']) === null || _a === void 0 ? void 0 : _a.uid;
if (!uid)
return res.status(401).send();
const appid = req.params.appid;
const app = await application_1.getApplicationByAppid(appid);
if (!app)
return res.status(422).send('invalid appid');
const roles = application_1.getUserGroupsOfApplication(uid, app);
if (!roles.length) {
return res.status(403).send();
}
const permissions = permission_1.getActionsOfRoles(roles);
const exp = Math.floor(Date.now() / 1000) + 60 * 60 * config_1.default.TOKEN_EXPIRED_TIME;
let debug_token = undefined;
if (permissions.includes(actions_1.FunctionActionDef.InvokeFunction)) {
debug_token = token_1.getToken({ appid, type: 'debug', exp }, app.config.server_secret_salt);
}
let export_port = config_1.default.APP_SERVICE_DEPLOY_URL_SCHEMA === 'http' ? config_1.default.PUBLISH_PORT : config_1.default.PUBLISH_HTTPS_PORT;
const app_deploy_host = config_1.default.APP_SERVICE_DEPLOY_HOST + ':' + export_port;
const app_deploy_url_schema = config_1.default.APP_SERVICE_DEPLOY_URL_SCHEMA;
const oss_external_endpoint = config_1.default.MINIO_CONFIG.endpoint.external;
const oss_internal_endpoint = config_1.default.MINIO_CONFIG.endpoint.internal;
const spec = await application_spec_1.ApplicationSpecSupport.getValidAppSpec(appid);
app.config = undefined;
return res.send({
data: {
application: app,
permissions,
roles,
debug_token,
app_deploy_host: thatUrl(app_deploy_host),
app_deploy_url_schema: thatUrl(app_deploy_url_schema),
oss_external_endpoint: thatUrl(oss_external_endpoint),
oss_internal_endpoint: thatUrl(oss_internal_endpoint),
spec
}
});
}
function thatUrl(originUrl) {
let modifiedString = originUrl.replace(/http/g, "https");
modifiedString = modifiedString.replace(/:8000/g, "");
return modifiedString;
}

这样返回的值就是https, 也没用端口号, 是正常的https请求。
记得重启 lafyun/system-server 容器。
改天在编排地方加上挂载, 就能在外面修改了。


本站由 钟意 使用 Stellar 1.28.1 主题创建。
又拍云 提供CDN加速/云存储服务
vercel 提供托管服务
湘ICP备2023019799号-1
总访问 次 | 本页访问