Nginx location matching everything ending with favicon.ico

Nginx locates the path to the file by concatenating the value of root with the value of the URI, so in your example, the URI /foo/favicon.ico will be searched for at /u/static/foo/favicon.ico.

Use try_files to force Nginx to look for a single static file. For example:

location ~* /favicon\.ico$ {
    root /u/static;
    try_files /favicon.ico =404;

The try_files statement requires at least two parameters, but the =404 will never be reached. See this document for details.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top