Is there a way to get one Static IP address for a Heroku Server? I'm trying to integrate various API's which ask for an IP address. Because of Heroku's server setup, you never have one server with a static IP - instead your IP is dynamic.

I've looked into add-ons like Proximo, however this appears to be a paid-for solution. Is there a solution where you have a static IP that you don't have to pay for?

有帮助吗?

解决方案

You can use QuotaGuard Static Heroku add-on.

QuotaGuard can be attached to a Heroku application via the command line:

$ heroku addons:add quotaguardstatic

After installing, the application should be configured to fully integrate with the add-on. When you sign up you will be provided with a unique username and password that you can use when configuring your proxy service in your application

A QUOTAGUARDSTATIC_URL setting will be available in the app configuration and will contain the full URL you should use to proxy your API requests. This can be confirmed using the next command:

$ heroku config:get QUOTAGUARDSTATIC_URL
http://user:pass@static.quotaguard.com:9293 

All requests that you make via this proxy will appear to the destination server to originate from one of the two static IPs you will be assigned when you sign up.

You can use A simple HTTP and REST client for Ruby for detecting your IP:

$ gem install rest-client

Next, you can run the below example in an IRB session and verify that the final IP returned is one of your two static IPs.

$ irb

>require "rest-client"

>RestClient.proxy = 'http://user:pass@static.quotaguard.com:9293'

>res = RestClient.get("http://ip.jsontest.com")

That's it:)

其他提示

Fixie is another option. Fixie is an add-on that provides Heroku applications with a fixed set of static IP addresses for outbound requests. It is language- and framework-agnostic.

Fixie is easy to setup and has "get started" documentation (similar to the one for Python below) for Ruby, Node, Java, Go here. Here is the one for Python.

First you need to sign up for the free plan:

$ heroku addons:open fixie
Opening fixie for sharp-mountain-4005…

Next, the FIXIE_URL will be set as environment variable. To route a specific request through Fixie using requests:

import os, requests
proxyDict = { 
              "http"  : os.environ.get('FIXIE_URL', ''), 
              "https" : os.environ.get('FIXIE_URL', '')
            }
r = requests.get('http://www.example.com', proxies=proxyDict)

Using urllib2 the same functionality will look like this:

import os, urllib2
proxy  = urllib2.ProxyHandler({'http': os.environ.get('FIXIE_URL', '')})
auth   = urllib2.HTTPBasicAuthHandler()
opener = urllib2.build_opener(proxy, auth, urllib2.HTTPHandler)
response = opener.open('http://www.example.com')
html = response.read()

In both cases, these requests would come through a known IP address assigned by Fixie.

You can use Nginx as your reserve proxy. Edit your nginx.conf and set proxy_pass. Make sure to set proxy_set_header to your herokuapp

    upstream backend  {

            server xxx.talenox.com;

    }

    server {

            listen          80;

            server_name     rpb1.talenox.com;

            location / {

                    proxy_pass              http://backend;

                    proxy_redirect          off;

                    proxy_set_header        X-Forwarded-For $remote_addr;

                    proxy_set_header        Host ‘xxxxx.herokuapp.com’;

            }

    }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top