App Engine 生产中代理服务器后面的 URLFetch
在 Google App Engine 上使用 urlfetch 时是否可以指定代理服务器?
具体来说,每次我使用 urlfetch 进行调用时,我都希望 GAE 通过代理服务器。我想在生产中做到这一点,而不仅仅是开发人员。
我想使用代理,因为使用 google 的出站 IP 地址存在问题(速率限制、没有静态出站 IP、有时被列入黑名单等)。如果您可以编辑 http 消息本身,设置代理通常很容易,但 GAE 的 API 似乎不允许您这样做。
Is there a way to specify a proxy server when using urlfetch on Google App Engine?
Specifically, every time I make a call using urlfetch, I want GAE to go through a proxy server. I want to do this on production, not just dev.
I want to use a proxy because there are problems with using google's outbound IP addresses (rate limiting, no static outbound IP, sometimes blacklisted, etc.). Setting a proxy is normally easy if you can edit the http message itself, but GAE's API does not appear to let you do this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您始终可以自己推出:
如果目标固定:只需在代理服务器上设置固定端口转发即可。然后将请求从 GAE 发送到代理。如果您有多个目的地,请在单独的端口上设置转发,每个目的地一个。
如果是动态目标(太多而无法通过固定端口转发处理),您的 GAE 应用会添加一个包含最终目标的自定义 http 标头 (
X-Something
),然后连接到自定义代理。自定义代理检查此字段并将请求转发到目的地。You can always roll your own:
In case of fixed destination: just setup a fixed port forwarding on a proxy server. Then send requests from GAE to proxy. If you have multiple destinations, then set forwarding on separate ports, one for each destination.
In case of dynamic destination (too much to handle via fixed port forwarding), your GAE app adds a custom http header (
X-Something
) containing final destination and then connects to custom proxy. Custom proxy inspects this field and forwards the request to the destination.我们遇到了这个问题并联系了 Google Cloud 支持。他们建议我们灵活使用 Google App Engine 以及一些 app.yaml 设置、自定义网络和 ip 转发 NAT 网关实例。
这对我们不起作用,因为 App Engine Standard 的许多核心功能并未在 App Engine Flex 中实现。本质上,我们需要重写我们的产品。
因此,为了使适用的 URL 获取请求看起来具有静态 IP,我们创建了一个自定义代理: https: //github.com/csgactuarial/app-engine-proxy
出于冗余原因,我建议将其实现为多区域、多区域、负载平衡系统。
We ran into this issue and reached out to Google Cloud support. They suggested we use Google App Engine flexible with some app.yaml settings, custom network, and an ip-forwarding NAT gateway instance.
This didn't work for us because many core features from App Engine Standard are not implemented in App Engine Flexible. In essence we would need to rewrite our product.
So, to make applicable URL fetch requests appear to have a static IP we made a custom proxy: https://github.com/csgactuarial/app-engine-proxy
For redundancy reasons, I suggest implementing this as a multi region, multi zone, load balanced system.