修复反向代理调用会使用暴露端口的问题
This commit is contained in:
parent
f58187d3b4
commit
71c6f96f2a
|
@ -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`|-|
|
||||
|
||||
内部暴露的端口
|
||||
-
|
||||
|
|
|
@ -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(),
|
||||
|
|
Loading…
Reference in New Issue