Eu tenho dois locais na configuração do nginx que funcionam:
location ^~ /media/ {
proxy_pass http://backend.example.com;
}
location ^~ /static/ {
proxy_pass http://backend.example.com;
}
Como posso combinar esses dois em um único local?
O que já fiz:
Eu tentei esta sugestão
location ~ ^/(static|media)/ {
proxy_pass http://backend.example.com;
}
mas não funciona para mim.
Além disso, quando não uso back-ends, a seguinte configuração está funcionando corretamente:
location ~ ^/(static|media)/ {
root /home/project_root;
}
update (algumas strings do log)
xx.xx.xx.xx - - [31/Dec/2013:13:48:18 +0000] "GET /content/11160/ HTTP/1.1" 200 5310 "-" "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36 OPR/18.0.1284.68"
xx.xx.xx.xx - - [31/Dec/2013:13:48:18 +0000] "GET /static/font-awesome/css/font-awesome.min.css HTTP/1.1" 404 200 "http://www.example.com/content/11160/" "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome$
xx.xx.xx.xx - - [31/Dec/2013:13:48:18 +0000] "GET /static/bootstrap/css/bootstrap.min.css HTTP/1.1" 404 200 "http://www.example.com/content/11160/" "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.$
xx.xx.xx.xx - - [31/Dec/2013:13:48:18 +0000] "GET /static/css/custom.css HTTP/1.1" 404 200 "http://www.example.com/content/11160/" "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/53$
xx.xx.xx.xx - - [31/Dec/2013:13:48:18 +0000] "GET /static/colorbox/colorbox.css HTTP/1.1" 404 200 "http://www.example.com/content/11160/" "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Sa$
xx.xx.xx.xx - - [31/Dec/2013:13:48:18 +0000] "GET /static/colorbox/jquery.colorbox-min.js HTTP/1.1" 404 200 "http://www.example.com/content/11160/" "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.$
xx.xx.xx.xx - - [31/Dec/2013:13:48:18 +0000] "GET /static/js/scripts.js HTTP/1.1" 404 200 "http://www.example.com/content/11160/" "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537$
SOLUÇÃO
Na verdade, minha solução funciona bem:
location ~ ^/(static|media)/ {
root /home/project_root;
}
e o problema não tem nada a ver com back-ends. Como Guido Vaccarella notou corretamente, apenas seguia outro location ~ ...
que combinava, para que o meu location ~ ...
não tivesse chance de correr.