nginx serving corrupt images

Maxim Dounin mdounin at mdounin.ru
Thu Feb 23 14:17:26 UTC 2023


Hello!

On Thu, Feb 23, 2023 at 08:13:54AM -0500, Saint Michael wrote:

> Suppose that my default html file forn a location is xyz.html, but there
> are hundreds. What is the canonical way to specify that and only that file
> for a / {}.

Locations are for a given URI prefix, not for a particular file.  
Locations define a configuration to be used for matching requests.  
See http://nginx.org/r/location for the detailed description of 
the location directive.

When mapping requests to the files, nginx simply concatenates the 
document root, as defined by the "root" directive, and URI from 
the requests.  For example, given "/path/to/html" root and a request 
to "/xyz.html", nginx will return the "/path/to/html/xyz.html" file.

If you want nginx to return only the particular file to all 
requests matched by the location, the most simple approach would 
be to use a rewrite (http://nginx.org/r/rewrite) to change the 
URI:

    location / {
        rewrite ^ /xyz.html break;
    }

Note though that this is not going to be a good solution to the 
issues with likely non-existing files you are facing.  Rather, 
this will make such issues impossible to debug, and is generally 
not recommended - unless you have good reasons to implement 
something like this.  Instead, I would recommend using normal 
request processing and let nginx to normally return files under 
the document root and reject requests to non-existing files.

Hope this helps.

-- 
Maxim Dounin
http://mdounin.ru/


More information about the nginx mailing list