error_page custom 404 page
Maxim Dounin
mdounin at mdounin.ru
Wed Jun 12 15:54:35 UTC 2024
Hello!
On Wed, Jun 12, 2024 at 05:11:50PM +0200, Marcello Lorenzi wrote:
> the 404 page is hosted on the same server.
This doesn't matter. When you write
> > > error_page 404 =404 https://$host/404/;
in your configuration, that is, as long as the error page URI
starts with something like "https://" or "http://", the "=404"
part does nothing: it is simply ignored, and [free]nginx returns a
302 redirect to the user. (When returning redirections, it is
only possible to change the status code to other redirection
status codes: 301, 302, 303, 307, and 308. See
http://freenginx.org/r/error_page for details.)
If/when the client follows the redirect and requests the URL
specified, it would be a new request, which is served according to
the configuration for this request. That is, if the is a static
file, it will be returned with the status code 200, much like any
normal static file.
If you want [free]nginx to respond with the particular content and
the 400 status code, consider using error_page URI as an absolute
path within the server in question, that is, starting with "/":
error_page 404 /404/;
This will instruct [free]nginx to do an internal redirect to the
specified URI, and return it along the status code 404.
Hope this helps.
--
Maxim Dounin
http://mdounin.ru/
More information about the nginx
mailing list