Get Nginx to call a PHP file to handle 404 errors in php-fpm

I am trying to configure Nginx to send all 404 files to a php file for further processing. I have no job. With try_files I get 404 by default and without try_files I don't get any input file. This is what I have so far:

server { listen 192.168.100.44:80; location / { index index.html; } root /var/www/test.example.com; error_page 404 /404.php; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; # pass the PHP s to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { #try_files $uri = 404; fastcgi_pass unix:/tmp/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } 
+4
source share
1 answer

The answer was to add a line: fastcgi_intercept_errors on;

Then, to process 404 and possibly return another status code from a PHP script: error_page 404 / 404.php; I just had to replace it with: error_page 404 = / 404.php;

Thanks to the kind people on the Nginx IRC channel who spent a few minutes of their time showing me the right direction.

+6
source

Source: https://habr.com/ru/post/1443279/


All Articles