user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
geo $remote_addr $geo {
default 0;
# 10.0.0.66/32 1;
10.0.0.65/32 2;
10.0.0.0/24 3;
}
upstream server_65 {
server 10.0.0.65:80;
}
upstream server_66 {
server 10.0.0.66:80;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
if ($geo = 1) {
#return 200 'this is for 10.0.0.66';
proxy_pass http://server_66;
}
if ($geo = 2) {
#return 200 'this is for 10.0.0.65';
proxy_pass http://server_65;
}
if ($geo = 3) {
#return 200 'this is for 10.0.0.0/24';
}