3

首先感谢您的帮助,我试图解决这个问题好几天

我知道可以通过其浮动 IP(您可以分配给 Droplet 的可公开访问的静态 IP 地址)路由来自 DigitalOcean 液滴的出站流量。

所以,我的液滴有 2 个 ip(常规和浮动 ip)正如此链接https://www.digitalocean.com/community/questions/send-outbound-traffic-over-floating-ip中所建议的,我找到了我的液滴的“锚IP”与

ip addr show eth0

我想用我的IP作为代理用python发出请求。我可以做这个?例如,如下所示:

import requests

proxies = {
    'http': 'http://XX.XX.XX.XX:YY',
    'https': 'http://XX.XX.XX.XX:YY',
}

# Create the session and set the proxies.
s = requests.Session()
s.proxies = proxies

# Make the HTTP request through the session.
r = s.get('https://www....')

XX.XX.XX.XX 是我的主播ip

YY -> 我必须使用什么端口?

我必须向我的防火墙 (UFW) 添加一些规则吗?

提前致谢

4

1 回答 1

4

首先,在您的 Droplet 上分配一个浮动 IP。

  1. 安装鱿鱼

    apt-get update apt-get install -y squid

  2. 配置 squid 代理:在 Google 上搜索如何进行基本配置。

  3. 找到你的液滴的“锚IP”

    ip addr show eth0

这是一个输出示例:

inet "YOUR_IP1"/20 brd 123.456.789.012 scope global eth0
   valid_lft forever preferred_lft forever

inet "YOUR_IP2"/16 brd 12.34.567.890 scope global eth0
   valid_lft forever preferred_lft forever
  1. 现在,您的液滴有 2 个 ip:YOUR_IP1YOUR_IP2

将这些行添加到 /etc/squid/squid.conf:

acl myip_1 myip YOUR_IP1
tcp_outgoing_address YOUR_IP1 myip_1

acl myip_2 myip 10.17.0.5
tcp_outgoing_address 10.17.0.5 myip_2

import requests

proxies = {
    'http': 'http://PUBLIC_IP:PORT',
    'https': 'http://PUBLIC_IP:PORT', 
}

# Create the session and set the proxies. 
s = requests.Session() 
s.proxies = proxies

# Make the HTTP request through the session. 
r = s.get('https://www....')
于 2018-04-02T21:59:33.753 回答