如果你之前在nginx配置当中,写过类似的逻辑:
location /some_url_prefix {
if (!-e $request_filename) {
proxy_pass http://172.17.0.21:3333;
}
proxy_http_version 1.1;
# 各种配置逻辑
}
location /other_url_prefix {
if (!-e $request_filename) {
proxy_pass http://172.17.0.21:3333;
}
# 与上面代码块同样的逻辑
proxy_http_version 1.1;
# 各种配置逻辑
}你完全可以简化它们,写成这样:
location ~ ^(/some_url_prefix|/other_url_prefix) {
if (!-e $request_filename) {
proxy_pass http://172.17.0.21:3333;
}
proxy_http_version 1.1;
# 各种配置逻辑
}这样让代码看起来更简洁一些。