[英]How to setup QuotaGuard Static for a Rails app hosted on heroku?
I'm trying to setup my heroku app to have an static IP using QuotaGuard (I know proximo is the other option, but it's pretty expensive). 我正在尝试使用QuotaGuard设置我的heroku应用程序以获得静态IP(我知道proximo是另一种选择,但它非常昂贵)。
I added the heroku QuotaGuard Static addon and got the two IPs it generates as well as the proxy url. 我添加了heroku QuotaGuard静态插件,并获得了它生成的两个IP以及代理URL。
What is my next step? 我下一步要做什么? (aka how do I tell my Rails app to use the proxy provided by QuotaGuard)
(又如何告诉我的Rails应用程序使用QuotaGuard提供的代理)
Most likely a bit too late to answer this question, but still. 回答这个问题很可能有点太迟了,但仍然如此。
Like you said, the first step to configuring QuotaGuard Static is provisioning the addon on Heroku (either via the Web Interface or the Heroku CLI). 如您所说,配置QuotaGuard Static的第一步是在Heroku上配置插件(通过Web界面或Heroku CLI)。 From there, you are able to get your two outbound IPs, and your proxy URL.
从那里,您可以获得两个出站IP和代理URL。 The two IPs you were given should be whitelisted on whichever remote service you are trying to access.
您尝试访问的任何远程服务都应将您提供的两个IP列入白名单。
As you mentioned, the documentation gives you a couple of samples using Rest Client for Ruby on Rails. 正如您所提到的,文档为您提供了一些使用Rest Client for Ruby on Rails的示例。 This snippet should pretty much go anywhere you want to access whichever resource you need to access via the static IP Addresses.
这个代码段应该可以随意访问您需要通过静态IP地址访问的任何资源。 Assuming you want to access a Web Service hosted on an Amazon EC2 instance with elastic IP 1.2.3.4, your would write:
假设您想要使用弹性IP 1.2.3.4访问托管在Amazon EC2实例上的Web服务,您可以写:
RestClient.proxy = ENV["QUOTAGUARDSTATIC_URL"]
res = RestClient.get("http://1.2.3.4/yourWebService")
And from there process the response stored in res
appropriately. 并从那里处理适当存储在
res
中的响应。 This code would go in say whichever controller's method you'll be using to access the remote web service. 这段代码将说明您将用于访问远程Web服务的控制器方法。 In this case, you also need to add the Rest Client to your controller, so at the top of that file you shoud also add
require "rest-client"
. 在这种情况下,您还需要将Rest Client添加到控制器,因此在该文件的顶部,您还应添加
require "rest-client"
。 Don't forget to add the rest-client
gem to your Gemfile. 不要忘记将
rest-client
gem添加到Gemfile中。
Summing up, basically the snippets from the documentation go wherever it is you want to use the proxy to access a remote service requiring a fixed, whitelisted set of IP addresses. 总而言之,基本上文档中的代码片段无论您希望使用代理来访问需要固定的白名单IP地址的远程服务。
Source: https://devcenter.heroku.com/articles/quotaguardstatic 资料来源: https : //devcenter.heroku.com/articles/quotaguardstatic
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.