'Nginx - how to restrict outbound traffic

Setup

AWS load balancer forward requests from example.com/(internalIP) to a pool of nginx. Nginx will have to grab that url (example.com/internalIP) and forward the request to that specific "internalIP".

The nginx pool need to have internet access (security tool installed on the nginx ec2 needs it) so I can't restrict the aws security group of the nginx pool to a specific subnet of private ip's.

PROBLEM

Given that setup I need to find an nginx configuration that will only forward to a specific subnet of private ips. This will avoid access to our infrastructure using any private ip



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source