nginx upstream
upstream :,
Syntax
upstream name { ... }Parameters
| Parameters | Description | Examples | Level |
|---|---|---|---|
least_conn |
least_conn; |
Common | |
ip_hash |
IP () | ip_hash; |
Common |
hash |
hash $request_uri consistent; |
Advanced | |
keepalive |
keepalive 32; |
Advanced | |
down |
server 127.0.0.1:3001 down; |
Common |
Examples
(IP Hash)
upstream app {
ip_hash;
server 192.168.1.10:8080;
server 192.168.1.11:8080;
server 192.168.1.12:8080;
}IP
upstream backend {
server 127.0.0.1:3000;
keepalive 32;
}
server {
location / {
proxy_pass http://backend;
proxy_http_version 1.1;
proxy_set_header Connection "";
}
}TCP
upstream app_v1 { server 127.0.0.1:3001;
}
upstream app_v2 { server 127.0.0.1:3002;
}
server { location / { # 10% New set $backend app_v1; if ($cookie_version = "v2") { set $backend app_v2; } proxy_pass http://$backend; }
}Cookie
Common Errors
keepaliveproxy_http_version 1.1 and Connection
Tips
- keepalive proxy_http_version 1.1
- ip_hash New
- consistent hash ip_hash