1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
upstream prod {
server 192.168.1.10;
server 192.168.1.11;
}
upstream pre-prod {
server 192.168.1.100;
}
server {
listen 80;
access_log /var/log/nginx/access .log main;
set $web_backend prod;
if ($remote_addr ~ "123.123.123.123" ) {
set $web_backend pre-prod;
}
location / {
proxy_pass http: // $web_backend;
include proxy.conf;
}
}
|
1
2
3
4
5
6
7
8
9
10
11
|
server {
listen 80;
access_log /var/log/nginx/access .log main;
set $rootdir "/var/www/html" ;
if ($remote_addr ~ "123.123.123.123" ) {
set $rootdir "/var/www/test" ;
}
location / {
root $rootdir;
}
}
|
根据Cookie实现灰度发布
根据Cookie查询version值,如果该version值为v1转发到host1,为v2转发到host2,都不匹配的情况下转发默认。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
upstream host1 {
server 192.168.2.46:2001 weight=1; #轮询服务器和访问权重
server 192.168.2.46:2002 weight=2;
}
upstream host2 {
server 192.168.1.155:1111 max_fails=1 fail_timeout=60;
}
upstream default {
server 192.168.1.153:1111 max_fails=1 fail_timeout=60;
}
map $COOKIE_version $group {
~*v1$ host1;
~*v2$ host2;
default default;
}
lua_shared_dict ip_blacklist 1m;
server {
listen 80;
#set $group “default”;
#if ($http_cookie ~* “version=v1”){
# set $group host1;
#}
#if ($http_cookie ~* “version=v2”){
# set $group host2;
#}
location / {
access_by_lua_file lua/ip_blacklist.lua;
proxy_pass http://$group;
}
}