Last active
January 23, 2024 10:30
-
-
Save metajiji/0f8cae54434868d5955742f3c52eb27f to your computer and use it in GitHub Desktop.
NGINX ANTILOOPA цикл по проксям, синий трактор едет к нам
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Define default virtualhost on the every node | |
# | |
server { | |
listen 80 default_server; | |
server_name _; | |
return 306; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Main upstream proxy server | |
# | |
map $cookie_NGINX_PROXY_BACKEND_NODE $_node { | |
default node01; | |
node02 $cookie_NGINX_PROXY_BACKEND_NODE; | |
node03 $cookie_NGINX_PROXY_BACKEND_NODE; | |
} | |
server { | |
listen 80; | |
server_name server-name.tld; | |
root /usr/share/nginx/html; | |
index index.html index.htm; | |
location / { | |
set $NGINX_PROXY_BACKEND_ANTILOOPA 'start'; # mark first request | |
try_files /dev/null @$_node; | |
} | |
location @node01 { | |
add_header Set-Cookie NGINX_PROXY_BACKEND_NODE=node01; | |
proxy_pass http://255.255.0.3; | |
proxy_set_header Host $host; | |
proxy_set_header X-Forwarded-For $remote_addr; | |
proxy_intercept_errors on; | |
recursive_error_pages on; | |
error_page 306 = @node02; | |
} | |
location @node02 { | |
add_header Set-Cookie NGINX_PROXY_BACKEND_NODE=node02; | |
proxy_pass http://255.255.0.4; | |
proxy_set_header Host $host; | |
proxy_set_header X-Forwarded-For $remote_addr; | |
proxy_intercept_errors on; | |
recursive_error_pages on; | |
error_page 306 = @node03; | |
} | |
location @node03 { | |
add_header Set-Cookie NGINX_PROXY_BACKEND_NODE=node03; | |
proxy_pass http://255.255.0.5; | |
proxy_set_header Host $host; | |
proxy_set_header X-Forwarded-For $remote_addr; | |
proxy_intercept_errors on; | |
recursive_error_pages on; | |
error_page 306 = @end; | |
} | |
location @end { | |
recursive_error_pages on; | |
error_page 464 = @node01; # If not first run, go stop loop and raise 502 | |
if ($NGINX_PROXY_BACKEND_ANTILOOPA = 'start') { | |
set $NGINX_PROXY_BACKEND_ANTILOOPA 'end'; # mark not first request | |
return 464; # First run, go to first node | |
} | |
if ($NGINX_PROXY_BACKEND_ANTILOOPA = 'end') { | |
return 502; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment