使用 Google Compute Engine 作为 Google App Engine 网络应用的代理 [英] Using Google Compute Engine as a proxy for a Google App Engine web app

查看:28
本文介绍了使用 Google Compute Engine 作为 Google App Engine 网络应用的代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Google App Engine 上有一个 Java 网络应用程序,它向外部 API 发出请求.该 API 最近需要将 IP 地址列入白名单才能访问其服务.因为 GAE 不提供静态 IP,我知道一种解决方案是设置 GCE 实例(使用静态 IP)并将其用作 GAE 应用程序发出的外部请求的代理.

I have a Java web app on Google App Engine which makes requests to an external API. The API recently requires the whitelisting of IP addresses in order to access its services. Because GAE does not offer static IPs, I understand that one solution is to set up GCE instance (with a static IP) and use it as a proxy for external requests made by the GAE app.

我已经使用 Debian GNU/Linux 9 设置了一个 f1-micro 实例,并根据 文档.

I have set up a f1-micro instance with Debian GNU/Linux 9, and have created a static external IP address as per the documentation.

如何安装 nginx 并设置 GAE 以将请求路由到 GCE 代理?

How do I install nginx and set up GAE to route requests to the GCE proxy?

推荐答案

我们遇到了一个类似的问题,客户需要将我们的 IP 地址列入白名单.我们通过以下方式解决了这个问题:

We faced a similar issue with a client who needed our IP address to be whitelisted. We solved the issue by:

  1. 使用静态 IP 地址启动 Compute Engine.这是我们给客户的 IP 地址
  2. 在计算引擎上安装 Squid (https://help.ubuntu.com/lts/serverguide/squid.html)
  3. 然后,我们通过代理服务器重定向了来自 App Engine 的所有调用.您没有列出您使用的语言,但对于 PHP,这意味着将以下两行添加到我们的 CURL 操作中:

  1. Spinning up a Compute Engine with a static IP address. This is the IP address we gave to our client
  2. Installed Squid on the compute engine (https://help.ubuntu.com/lts/serverguide/squid.html)
  3. We then redirected all calls from the App Engine through the proxy server. You didn't list what language you are using but for PHP, that meant adding the following two lines to our CURL operations:

curl_setopt($ch, CURLOPT_PROXY, "http://" . $_SERVER['SQUID_PROXY_HOST'] . ":" . $_SERVER['SQUID_PROXY_PORT'] );

curl_setopt($ch, CURLOPT_PROXY, "http://" . $_SERVER['SQUID_PROXY_HOST'] . ":" . $_SERVER['SQUID_PROXY_PORT'] );

curl_setopt($ch, CURLOPT_PROXYUSERPWD, $_SERVER['SQUID_PROXY_USER'] . ":" . $_SERVER['SQUID_PROXY_PWD']);

curl_setopt($ch, CURLOPT_PROXYUSERPWD, $_SERVER['SQUID_PROXY_USER'] . ":" . $_SERVER['SQUID_PROXY_PWD']);

需要注意的一点是,根据您拨打的电话数量,微实例可能不适合您.我们最初在一个微型盒子上设置了我们的代理服务器,但每隔几天就不得不重新启动它.我们最终切换到标准盒子,此后没有遇到任何问题.

One thing to note is that depending on the number of calls you are making, a micro instance might not work for you. We initially setup our proxy server on a micro box but were having to restart it every few days. We ended up switching to a standard box and have not run into any problems since.

这篇关于使用 Google Compute Engine 作为 Google App Engine 网络应用的代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆