0

I'm trying to set up a 404 file which handles unknown url requests using the error_page directive, the file im trying to root it to is a .php file which is in the same directory as the route.

The problem i cannot figure out is that as soon as i create a 404 route and define the location it seems to download the file rather than serve it. To test i wasn't going mental i put additional php files up outside the 404 rule and they run and return content but the 404 rule file just downloads

snippet of my config is

root /var/www/itn;
index index.php index.html index.htm;

location / {
    try_files $uri $uri/ /index.php$is_args$args;
}

location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
access_log        off;
log_not_found     off;
expires           1d;
}

error_page 404 /404.php;
location = /404.php{
    root /var/www/itn;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
    root /var/www/error/html;
}

location ~ \.php$ {
    fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_intercept_errors on;
    include fastcgi_params;
}

quick search solutions suggested the fastcgi_intercept_errors but switching both on and off doesn't change help, also noticed if i put in a bogus url www.site.com/somecraphere it goes to a site cannot be reached ERR_INVALID_RESPONSE so i think the 404 rule is working it just cant do anything with the file.

All suggestions, improvements and corrections are appreciated

Jimjebus
  • 3
  • 1
  • 3

1 Answers1

0

Turns out im not a smart man

without try files included within the location ~ \.php$

        try_files $uri /404.php;

it won't execute the php, instead it will try to serve it in the same way it would serve a image or document.

Jimjebus
  • 3
  • 1
  • 3