# Server A. # --------- server { listen 8000; location / { add_header Content-Type text/html; set $html_page '\n'; set $html_page '${html_page}

Hello! This is the first HTTP server!

\n'; set $html_page '${html_page}\n'; return 200 $html_page; } } # Server B. # --------- server { listen 9000; location / { add_header Content-Type text/html; set $html_page '\n'; set $html_page '${html_page}

Ahoy! This is the second HTTP server!

\n'; set $html_page '${html_page}\n'; return 200 $html_page; } } # Redirection proxy # ----------------- # User environment mapping definition map $remote_user $target { Alice server_a; Bob server_b; } server { listen 80; if ($target ~ "server_a|^$") { # server_a or regex for empty string set $target_port 8000; } if ($target = "server_b" ) { set $target_port 9000; } location / { proxy_pass http://127.0.0.1:$target_port; } }