网络知识 娱乐 nginx 使用map批量反向代理

nginx 使用map批量反向代理

http {

...

map $uri $match {

~^/csweb/(.*) http://10.0.8.13;

~^/rsxkweb/(.*) http://10.0.8.14;

~^/xjweb/(.*) http://10.0.8.18;

~^/kwweb/(.*) http://10.0.8.20;

~^/liweb/(.*) http://10.0.8.31;

~^/qqvweb/(.*) http://10.0.8.45;

~^/csapi/(.*) http://10.0.8.13:10000;

~^/rsxkapi/(.*) http://10.0.8.14:10000;

~^/(hbapi|api)/(.*) http://10.0.8.18:10000;

~^/qzapi/(.*) http://10.0.8.20:10000;

~^/liapi/(.*) http://10.0.8.31:10000;

~^/qqvapi/(.*) http://10.0.8.45:10000;

~^/wss http://10.0.8.43:9876;

}

server {

listen 80 ;

listen [::]:80 ;

server_name localhost;

location /wss {

proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_pass $match/;

proxy_http_version 1.1;

proxy_set_header Upgrade $http_upgrade;

proxy_set_header Connection "upgrade";

}

location ~ ^/[a-zA-Z]*/(.*)$ {

proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_pass $match/$1$is_args$args;

}

}

}