我试图支持云运行(和App )项目的大文件上传。有一些限制因素妨碍了通常的解决办法:
客户端是requirement
这使我得出结论,我应该设置一个前向代理,允许签名的URL通过我们的GCP项目/公司域绕过IT限制。我将在Compute Engine中使用运行nginx或squid或其他什么的实例来实现这一点,然后有一个负载均衡器,将某种模式的直接URL直接发送给前向代理,该代理将重写URL到正确的云存储签名URL并转发请求。
然而,这似乎是一个笨拙的解决方案。GCP有什么更简单的东西可以完成我想做的事情吗?
发布于 2022-06-07 13:04:39
我能够使用nginx代理云存储签名URL:
events {
worker_connections 1024;
}
http {
client_max_body_size 500M;
server {
listen 80;
listen [::]:80;
server_name mydomain;
location /storagepxy/ {
proxy_pass https://storage.googleapis.com/;
}
}
}
然后,我设置了一个GCP负载均衡器,将从/storagepxy/*
开始的任何请求定向到使用上述配置运行nginx的计算引擎实例组。
因此,我可以使用表单的请求来读取/写入云存储:
GET mydomain/storagepxy/[cloud storage signeduri]
PUT mydomain/storagepxy/[cloud storage signeduri]
因此,如果您有一个签名的URL,如:
https://storage.googleapis.com/example-bucket/cat.jpeg?X-Goog-Algorithm=
GOOG4-RSA-SHA256&X-Goog-Credential=example%40example-project.iam.gserviceaccount
.com%2F20181026%2Fus-central1%2Fstorage%2Fgoog4_request&X-Goog-Date=20181026T18
1309Z&X-Goog-Expires=900&X-Goog-SignedHeaders=host&X-Goog-Signature=247a2aa45f16
9edf4d187d54e7cc46e4731b1e6273242c4f4c39a1d2507a0e58706e25e3a85a7dbb891d62afa849
6def8e260c1db863d9ace85ff0a184b894b117fe46d1225c82f2aa19efd52cf21d3e2022b3b868dc
c1aca2741951ed5bf3bb25a34f5e9316a2841e8ff4c530b22ceaa1c5ce09c7cbb5732631510c2058
0e61723f5594de3aea497f195456a2ff2bdd0d13bad47289d8611b6f9cfeef0c46c91a455b94e90a
66924f722292d21e24d31dcfb38ce0c0f353ffa5a9756fc2a9f2b40bc2113206a81e324fc4fd6823
a29163fa845c8ae7eca1fcf6e5bb48b3200983c56c5ca81fffb151cca7402beddfc4a76b13344703
2ea7abedc098d2eb14a7
您可以通过以下方式代理:
https://mydomain/storagepxy/example-bucket/cat.jpeg?X-Goog-Algorithm=
GOOG4-RSA-SHA256&X-Goog-Credential=example%40example-project.iam.gserviceaccount
.com%2F20181026%2Fus-central1%2Fstorage%2Fgoog4_request&X-Goog-Date=20181026T18
1309Z&X-Goog-Expires=900&X-Goog-SignedHeaders=host&X-Goog-Signature=247a2aa45f16
9edf4d187d54e7cc46e4731b1e6273242c4f4c39a1d2507a0e58706e25e3a85a7dbb891d62afa849
6def8e260c1db863d9ace85ff0a184b894b117fe46d1225c82f2aa19efd52cf21d3e2022b3b868dc
c1aca2741951ed5bf3bb25a34f5e9316a2841e8ff4c530b22ceaa1c5ce09c7cbb5732631510c2058
0e61723f5594de3aea497f195456a2ff2bdd0d13bad47289d8611b6f9cfeef0c46c91a455b94e90a
66924f722292d21e24d31dcfb38ce0c0f353ffa5a9756fc2a9f2b40bc2113206a81e324fc4fd6823
a29163fa845c8ae7eca1fcf6e5bb48b3200983c56c5ca81fffb151cca7402beddfc4a76b13344703
2ea7abedc098d2eb14a7
注意:如果桶路径包含URL编码的字符(如冒号),则需要稍微复杂一些的nginx配置:
# This is a simple nginx configuration file that will proxy URLs of the form:
# https://mydomain/storagepxy/[signed uri]
# to
# https://storage.googleapis.com/[signed uri]
#
# For use in GCP, you'll likely need to create an instance group in compute engine running nginx with this config
# and then hook up a load balancer to forward requests starting with /storagepxy to it
worker_processes auto; # Auto should spawn 1 worker per core
events {}
http {
client_max_body_size 500M;
server {
listen 80; # IPv4
listen [::]:80; # IPv6
server_name mydomain;
location /storagepxy/ {
# To resolve storage.googleapis.com
resolver 8.8.8.8;
# We have to do it this way in case filenames have URL-encoded characters in them
# See: https://stackoverflow.com/a/37584637
# Also note, if the URL does not match the rewrite rules then return 400
rewrite ^ $request_uri;
rewrite ^/storagepxy/(.*) $1 break;
return 400;
proxy_pass https://storage.googleapis.com/$uri;
}
}
}
https://stackoverflow.com/questions/72521291
复制相似问题