Search code examples
nginxconfigurationuwsginginx-config

Nginx: If static file not found, try the same URL on webserver


I'm running a server that serves map tiles, by default from the /var/www/tiles directory. If a tile file is not found, I want nginx to try the tiles path on the uwsgi server like this: /tiles/9-250-250.png - the uwsgi app is setup to generate tiles dynamically and will return a file on that path.

This is the current nginx configuration:

server {
        listen 80;

        root /var/www;

        location /tiles/ {
        }

        location / {
                include uwsgi_params;
                uwsgi_pass unix:/home/one/wikiscape/wikiscape.sock;
        }
}

What do I need to add to the location /tiles/ {} directive to redirect (?) to the server if the file is not found?


Solution

  • It seems to be sufficient to add try_files $uri /$uri;

    location /tiles/ {
            try_files $uri /$uri;
    }