location ~ {
root /var/www/static1/;
root /var/www/static2/;
}
I tried the above,so that when /name.gif
is requested ,if /var/www/static1/name.gif
exists, then just use it as is;but if there isn't such a file,try to see if there's /var/www/static2/name.gif
, is it possible to configure nginx this way?
Assuming you're using nginx 0.7.24(?) or later, you can accomplish this with try_files:
Normally, having root inside location / is incorrect, but in this specific case, I don't think you want to set /var/www as your general root in case you end up adding other locations.
I'm fairly certain your exact configuration is not possible. To serve from multiple roots, you'd need to alias one root into your URL structure, something like this: