So, certain situations can arise (often times security) where you will need static IP addresses in front of your ELBs. Not everyone needs this but a rising number of people are starting to, and I will show you how. The only use case I’ve ran into this is on AWS, not anywhere else. But if it works it works.
Currently there are only two solutions I have found: HAProxy 1.6, and Nginx (goes back to versions farther than 3 years ago). Here’s how
In Nginx:
There is a configuration value called “resolver”, here is an example. It can be used in your http, server, or location context.
1 |
resolver <address> [valid=time] [ipv6=on|off]; |
An in use example:
1 2 3 4 5 6 7 8 9 10 11 |
server { ... resolver 10.1.1.1 valid=10s; ... location / { ... set $elb "myelb.us-east-1.elb.amazonaws.com"; proxy_pass http://$elb; ... } } |
This will force Nginx to update the DNS for example.com every 10s. In applications I have done we set this to 2s, because it works better for the amount of scaling up and down we do. Since doing this we haven’t seen any failures related to DNS resolution of ELBs.
As a side not, putting it in the http context does have some issues and you may end up with stale DNS data, even with valid=10s, etc.