Назад | Перейти на главную страницу

nginx отобразит image404.php, если изображение не найдено

Необходимость переместить .httacess в версию nginx: nginx / 1.11.2, большая часть из них прошла успешно, но одна перезапись все еще беспокоит меня.

##Return default placeholder image when image file on server not found
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteRule \.(gif|jpe?g|png) /image404.php [NC,L]

Вот что я сделал, но не работает

location ~* ^.+.(jpg|jpeg|gif|png|ico)$ {
    try_files $uri $uri/;
    error_page 404      /image404.php; #not working either /core/images/placeholder.jpg
    access_log      off;
    log_not_found       off;
    aio         on;
    sendfile        on;
    etag            on;
    expires         max;
    add_header      Pragma 'public, must-revalidate, proxy-revalidate';
    add_header      X-Frame-Options SAMEORIGIN;
}

/Core/images/placeholder.jpg существует и очень доступен через http, image404.php выглядит так

<?php

$file = $_SERVER['DOCUMENT_ROOT'] . '/core/images/placeholder.jpg';
$type = 'image/jpeg';
$filesize = filesize($file);
header("HTTP/1.0 404 Not Found");
header("Content-Type: $type");
header("Content-Length: $filesize");
readfile($file);

Вот мой php в файле conf

location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
try_files $uri $uri/ index.php;
fastcgi_pass   unix:var/run/php5-fpm.sock; #/var/run/php-fpm.sock;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
proxy_connect_timeout  600s;
proxy_send_timeout  600s;
proxy_read_timeout  600s;
fastcgi_send_timeout 600s;
fastcgi_read_timeout 600s;
include        fastcgi_params;
}

Я искал разные решения, но ни одно из них мне не помогло. nginx отображает не найденное изображение но только чтобы вернуть тот же результат :(

в файле журнала я вижу только это

tail -F /var/log/nginx/error.log | grep image404.php
2016/07/22 17:27:21 [error] 4906#4906: *34 rewrite or internal redirection cycle while internally redirecting to "index.php", client:  1.2.3.4, server: exsample.com, request: "GET /image404.php HTTP/1.1", upstream: "fastcgi://unix:var/run/php5-fpm.sock", host: "exsample.com"
2016/07/22 17:27:21 [error] 4906#4906: *30 rewrite or internal redirection cycle while internally redirecting to "index.php", client:  1.2.3.4, server: exsample.com, request: "GET /favicon.ico HTTP/1.1", host: "exsample.com", referrer: "http://exsample.com/image404.php"