Skip to content

Instantly share code, notes, and snippets.

@kmjones1979
Created April 14, 2016 20:18
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kmjones1979/2bee7dfd3000b64e166b42ef2eba0cf5 to your computer and use it in GitHub Desktop.
Save kmjones1979/2bee7dfd3000b64e166b42ef2eba0cf5 to your computer and use it in GitHub Desktop.
Example NGINX configuration to dynamically set the local IP address during socket creation
# Example of proxy_bind using variables using split_clients and map
events { worker_connections 2014; }
http {
default_type text/plain;
error_log /var/log/nginx/debug_error.log debug;
server {
listen 8098;
status_zone frontend;
return 200 "Results:
Server Address:\t $server_addr:$server_port
Network Remote Address:\t $remote_addr
Current time:\t\t $time_local
Request URI:\t\t $request_uri\n\n";
}
upstream backend {
zone backend 64k;
server 172.16.239.200:8098;
}
server {
listen 80;
location / {
proxy_pass http://backend;
proxy_bind $split_ip;
proxy_set_header X-Forwarded-For $remote_addr;
}
}
split_clients "$request_uri$remote_port" $split_ip {
10% 172.16.239.200;
10% 172.16.239.201;
10% 172.16.239.202;
10% 172.16.239.203;
10% 172.16.239.204;
10% 172.16.239.205;
10% 172.16.239.206;
10% 172.16.239.207;
10% 172.16.239.208;
* 172.16.239.209;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment