nginx返回特定端点的图像

时间:2018-10-05 21:14:29

标签: nginx

我想从nginx返回自定义图标,所以我添加了以下内容:

location ~ ^/favicon.ico {
    expires 2w;
    access_log off;
    try_files $uri /path/to/custom/ico.ico;
}

但是当我curl foo.com/favicon.ico时我得到了404。怎么会这样?

1 个答案:

答案 0 :(得分:0)

尝试

location = /favicon.ico {
    expires 2w;
    access_log off;
    alias /path/to/custom/ico.ico;
}

我放置=是因为using the “=” modifier it is possible to define an exact match of URI and location. If an exact match is found, the search terminates。因此它可能会更快一些。