我在nginx conf中有以下配置
location /request1 {
proxy_pass http://hostname:port/request1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
location /request2 {
proxy_pass http://hostname:port/request2;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
location /request3 {
proxy_pass http://hostname:port/request3;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
我想将它们合并到一个配置中,如
location ~ /(request1|request2|request3)/ {
proxy_pass http://hostname:port/$1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
我无法弄清楚语法。有人可以帮帮我吗?
回答我的问题:
以下适用于我:
location ~ ^/(request1|request2|request3) {
proxy_pass http://hostname:port;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
答案 0 :(得分:0)
请从匹配项中删除最后一个/
。另外,添加^
以确保从uri的开头开始匹配。
location ~ ^/(request1|request2|request3) {