如果你之前在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;
# 各種配置邏輯
}這樣讓代碼看起來更簡潔一些。