How do I force nginx to serve a custom 404 page while responding with a 404 header, without changing the address of the browser so the user can easily retype?
set $allowed 0; #(updated after comments)
error_page 404 /404page.html; #(updated after first answer, forgot to mention)
location = /authreq.html {
if ($allowed = 0){
# return 307 $scheme://$host/404page.html ; #works but should be 404
# return 404 "shows this message"; #does not redirect when inserting url instead of message
# rewrite ^ /404page.html break; #serves 404page.html and doesn't change browseraddress which is good, but sends a response header 200
# return 404 # invokes error_page directive with header 200
}
}
The whole configuration:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
server_name www.fellowshipmedia.eu;
server_name localhost;
root /usr/share/nginx/html;
index index.php index.html index.htm;
error_page 404 = /404page.html;
set $allowed 0;
location = /authreq.html {
if ($allowed = 0){
# return 307 $scheme://$host/404page.html ; #works but should be 404
# return 404 "shows this message"; #does not redirect when inserting url instead of message
return 404; #
# rewrite ^ /404page.html break; #serves 404page.html and doesn't change browseraddress which is good, but sends a response header 200
}
}
}