A
A
Alex2014-11-05 14:50:14
PHP
Alex, 2014-11-05 14:50:14

How to display custom 404 page on NGINX+PHP+FPM?

Dear developers, please help me, I don't fully understand how the NGINX+PHP+FPM bundle works.
OBJECTIVE : show the client my own 404 page dynamically generated in PHP, with a server response "404 Not Found", if we receive a response from the same PHP that such a page does not exist.
At the moment I have if PHP gives a response that the page does not exist and write ---> header("HTTP/1.0 404 Not Found");
- then the transition to my page occurs, but at the same time:

HTTP/1.1 302 Moved Temporarily
Server: nginx
Date: Wed, 05 Nov 2014 11:02:06 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep- alive
Keep-Alive: timeout=15
Location: /404/

---
and if you write in PHP ---> header("Status: 404 Not Found");
- then the transition to my page does not occur, nginx shows its 404 and, of course, the server response is already correct
HTTP/1.1 404 Not Found
Server: nginx

My experiments with:
fastcgi_intercept_errors on; Turned it off and on, didn't work.
location /404/ { } - tried all sorts of options, but did not achieve success.
Naturally, after each change, I restart nginx.
NGINX.conf (abbreviated):
http {
error_page 403 404 /404/;
error_page 500 502 504 /504/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-for $remote_addr;
proxy_ignore_client_abort on;
proxy_intercept_errors on;
proxy_redirect off;
proxy_store on;
server {
server_name namesite.ru;
location / {
rewrite ^/([^/]+).html$ /index.php?page=$1& last;
rewrite ^/([^/]+)/?(.*)$ /index.php?page=$1$2& last;
break;
root /accounts/namesite/www;
index index.php;
}
location ~ .php$ {
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_pass backend;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /accounts/namesite/www$fastcgi_script_name;
include fastcgi_params;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_intercept_errors on;
fastcgi_ignore_client_abort off;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
}
#location /404/ {
#}
}
upstream backend {
server;
}
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Grechushnikov, 2014-11-05
@maxyc_webber

asked the other day. intersepterrors = off to be done

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question