Skip to content

Instantly share code, notes, and snippets.

@ochinchina
Forked from kmjones1979/nginx.conf
Created October 31, 2018 04:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ochinchina/6510f27e466454e467aefef49c8619aa to your computer and use it in GitHub Desktop.
Save ochinchina/6510f27e466454e467aefef49c8619aa 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