美文网首页
如何在公司内网访问阿里云OSS

如何在公司内网访问阿里云OSS

作者: 昆猪IMK | 来源:发表于2019-12-04 15:50 被阅读0次

目前访问阿里云OSS有4中方式

1.网页控制台访问
2.oss browser工具访问
3.ossUtil命令行工具访问
4.SDK访问

以上方式都需通过endpoint地址或bucket访问域名来访问,目前这两个访问域名都可开通外网和内网两种域名,一般可结合当前的开发环境,配置对应的域名,或者配置化参数,开发时用外网,部署到ECS用内网。

但有一种情况是例外,就我目前的开发环境而言,是在公司内网开发的,通过VPN连接到阿里公有云的VPC,如果直接使用OSS内网访问域名访问,会报无法解析域名的错误。那么如何解决呢。
阿里官方的方案是通过ECS搭建nginx代解决的,具体步骤见以下链接:

https://tech.antfin.com/docs/2/107034#concept-ugx-y3n-qgb

目前只有ossUtil和SDK支持代理模式访问OSS
配置好nginx代理之后,ossUtil可通过设置代理参数来访问

ossutil64.exe ls oss://bucketname --proxy-host=http://10.0.x.xxx:18888

http://10.0.x.xxx:18888 是我配置的代理的bucket的访问域名对应的nginx ip和端口

使用SDK,在ProxyHost中设置http://10.0.x.xxx:18888后,访问OSS会报

Unable to execute HTTP request: Connect to oss-cn-shanghai-finance-1-pub-internal.aliyuncs.com:80 [bucketname.oss-cn-shanghai-finance-1-pub-internal.aliyuncs.com/100.100.36.24] failed: Connection refused: connect

如果直设置endpoint为代理地址http://10.0.x.xxx:18888,则会报必须使用三级域名

The bucket you are attempting to access must be addressed using OSS third level domain

如果不代理endpoint代理,而是代理bucket访问域名,则会报

StatusCode=403, ErrorCode=SignatureDoesNotMatch, ErrorMessage="The request signature we calculated does not match the signature you provided. Check your key and signing method

折腾了一番后,我用下面这个办法解决了问题:
将nginx代理端口设为80,在内网开发机器的 C:\Windows\System32\drivers\etc\hosts文件里添加nginx ip和endpoint内网访问域名的配置

10.0.x.xxx oss-cn-shanghai-finance-1-pub-internal.aliyuncs.com:80 [bucketname.oss-cn-shanghai-finance-1-pub-internal.aliyuncs.com

这样内网中使用SDK可以不用解析域名来访问OSS。
非官方方法,仅供参考。

相关文章

网友评论

      本文标题:如何在公司内网访问阿里云OSS

      本文链接:https://www.haomeiwen.com/subject/kcllgctx.html