Answer the question
In order to leave comments, you need to log in
How to set up NGINX forward proxy in docker with multiple public IP addresses with round-robin option?
There is an application in the form of a service in Docker that accesses external api.site1.com and api.site2.com
Docker is running on a hosting server with several external IPs (eth0, eth0:1, eth0:2).
The site has a limit on the number of requests from one IP.
It is necessary to configure nginx forward proxy in Docker so that each new request from the application through the proxy comes from the next IP address from the pool of public IP addresses (round-robin) of the hosting machine.
The question is, what should docker and docker-compose.yml look like to accomplish this task?
Answer the question
In order to leave comments, you need to log in
Let's say api.site1.com has the address 192.168.1.1, and on the network card there are three IP addresses 10.0.0.1, 10.0.0.2 and 10.0.0.3, then it should work:
iptables -A POSTROUTING -t nat -p tcp -d 192.168.1.1 --dport 80 \
-m statistic --mode nth --every 3 --packet 0 \
-j SNAT --to-source 10.0.0.1
iptables -A POSTROUTING -t nat -p tcp -d 192.168.1.1 --dport 80 \
-m statistic --mode nth --every 2 --packet 0 \
-j SNAT --to-source 10.0.0.2
iptables -A POSTROUTING -t nat -p tcp -d 192.168.1.1 --dport 80 \
-j SNAT --to-source 10.0.0.3
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question