nginx 's.png' 出现奇怪的 404 问题

nginx 's.png' 出现奇怪的 404 问题

此 URL 无效:http://mysite.co.uk/assets/images/whymysite/viewoptions.png

但是,如果我将 .png 末尾的“s”替换为任何其他标准字符(我到目前为止尝试过,效果很好。另外,我以前一直在使用视图选项.jpg- 效果很好。它似乎特别图像看起来就是这样。

我在尝试加载图像时遇到了一些其他令人困惑的 404 错误,我怀疑这可能是同一问题的症状,出于最后一刻的匆忙,我通过随机重命名图像来解决问题!

其他一切都按预期进行,但这让我抓狂!我是 nginx 新手,比系统管理员更擅长编程,所以请随意嘲笑我明显的错误,无论它是什么 :)

我对此网站的 nginx 配置是:

server {
    listen          80;
    server_name     mysite.co.uk;
    root            /var/www/mysite/public/;
    index           index.php index.html;

    access_log      /var/www/mysite/logs/access.log;
    error_log       /var/www/dmysite/logs/error.log;

    try_files       $uri    $uri/   /index.php?q=$uri&$args;

    location ~* .(jpg|jpeg|gif|css|png|js|ico|eot|svg|ttf|woff)$ {
            access_log        off;
            expires           30d;
    }

    # pass PHP scripts to FastCGI server listening on 127.0.0.1:9000

    location ~ \.php$ {
            include         fastcgi_params;
            fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
            try_files       $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_index   index.php;
            fastcgi_pass    127.0.0.1:9000;
    }

}

以下是一些日志条目。首先是“viewoptions.png”的错误日志条目

2011/09/28 17:24:34 [error] 4241#0: *11 open() "/var/www/mysite/public/assets/images/whymysite/viewoptions.png" failed (2: No such file or directory), client: 192.168.0.2, server: mysite.co.uk, request: "GET /assets/images/whymysite/viewoptions.png HTTP/1.1", host: "mysite.co.uk", referrer: "http://mysite.co.uk/why-mysite.php"

现在,其他文件名的 access.log 条目可以正常工作。使用不同的扩展名,删除“s”,添加一个或多个字符来替换“s”?都很好!

192.168.0.2 - - [28/Sep/2011:17:24:14 +0100] "GET /assets/images/whymysite/viewoptions.jpg HTTP/1.1" 304 0 "http://mysite.co.uk/why-mysite.php" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.186 Safari/535.1"
192.168.0.2 - - [28/Sep/2011:17:24:34 +0100] "GET /assets/images/whymysite/viewoptions.png HTTP/1.1" 404 201 "http://mysite.co.uk/why-mysite.php" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.186 Safari/535.1" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.186 Safari/535.1"
192.168.0.2 - - [28/Sep/2011:17:24:43 +0100] "GET /assets/images/whymysite/viewoption.png HTTP/1.1" 304 0 "http://mysite.co.uk/why-mysite.php"
192.168.0.2 - - [28/Sep/2011:17:24:59 +0100] "GET /assets/images/whymysite/viewoptionqqq.png HTTP/1.1" 200 3486 "http://mysite.co.uk/why-mysite.php" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.186 Safari/535.1"

答案1

只需删除此部分:

location ~* .(jpg|jpeg|gif|css|png|js|ico|eot|svg|ttf|woff)$ {
        access_log        off;
        expires           30d;
}

因为现在您只需要与浏览器缓存作斗争。

相关内容