nginx

1,匹配规则,以openresty为例,可以使用echo库

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
31
32
33
34
35
36
37
38
39
40
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-steam;
sendfile on;
keepalive_timeout 65;

server {
listen 80;
server_name localhost;
default_type text/html;

location / {
echo "hello nginx";
}

location = /a {
echo "=/a";
}

location ^~ /a {
echo "^~ /a";
}

location ^~ /a/b {
echo "^~ /a/b";
}

location ~ ^/[a-z]{
echo "~ ^/[a-z]"
}
location ~ ^/\w{
echo "~ ^/\w"
}

}
}

2,配置反向代理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-steam;
sendfile on;
keepalive_timeout 65;

server {
listen 80;
server_name localhost;
default_type text/html;

location / {
echo "hello world";
}

location /a/ {
proxy_pass http://yourdomain:80/;
}
}
}

3,负载均衡配置

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
31
32
33
34
35
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-steam;
sendfile on;
keepalive_timeout 65;

upstream group1{
server 192.168.0.12:80 weight=1;
server 192.168.0.12:81 weight=1;
}
server {
listen 80;
server_name localhost;
default_type text/html;

location / {
echo "hello world";
}

location /a/ {
proxy_pass http://yourdomain:80/;
}

# 负载均衡
location /b/ {
proxy_pass http://group1/;
}


}
}