The behavior of your browser is correct. The Location:
response header has no meaning for status code 404 (compare 14.30 Location and 10.4 Client Error 4xx).
Therefore the response's hypertext body is displayed in the browser - as specified by the HTTP specs for code 404 (see 10.4.5 404 Not Found).
To allow changing the HTTP response code from 404 to a different one (e.g. 302 for the temporary redirect), you have to configure Nginx error_page
directive accordingly:
error_page 404 = /404.php;
Without the equal sign (=
), it is not possible to change the status code with your PHP script:
header("Location: http://google.com"); # PHP sets 302 status code
SAPI: php5-fpm