修复反向代理调用会使用暴露端口的问题

This commit is contained in:
小王 2024-09-14 10:53:25 +08:00
parent f58187d3b4
commit 71c6f96f2a
2 changed files with 3 additions and 8 deletions

View File

@ -34,7 +34,7 @@ services:
|-|-|-|-|
|`NACOS_ADDR`| nacos注册地址 |`192.168.1.105:8848` |*|
|`SERVICE_PORT`| 指定外部可以向内访问的端口 |`8000`|*|
|`ORIGIN_URL`| 允许跨域的域名 |docker容器内ip|-|
|`ORIGIN_URL`| 允许跨域的网址 |`{docker容器内ip}:8000`|-|
内部暴露的端口
-

View File

@ -27,15 +27,10 @@ class Index
// thinkphp里面无法获取SERVER_ADDR变量会被nacos拦截替换
// 服务暴露的端口
$servicePort = $env->get('SERVICE_PORT', 8000);
if ($servicePort == 80) {
$servicePort = '';
} else {
$servicePort = ':' . $servicePort;
}
// 服务可以访问到的IP
$serverIP = $env->get('SERVER_ADDR');
// 允许跨域的域名
$originUrl = $env->get('ORIGIN_URL', $serverIP);
$originUrl = $env->get('ORIGIN_URL', $serverIP . ':' . $servicePort);
// 组装保存路径
$savename = \think\facade\Filesystem::disk('upload')->putFile('uploads', $file);
@ -46,7 +41,7 @@ class Index
'msg' => null,
'data' => [
"name" => $trueName,
"url" => '//' . $originUrl . $servicePort . '/' . $savename,
"url" => '//' . $originUrl . '/' . $savename,
// "url" => 'http://192.168.1.105:8080/file/' . $savename,
],
// 'env' => $env->get(),