Welcome! Log In Create A New Profile

Advanced

Nginx Custom 404 Custom Error Not Displaying [HELP]

Posted by nginx6382 
Nginx Custom 404 Custom Error Not Displaying [HELP]
April 20, 2012 09:13PM
I'm trying to get nginx to always show custom error pages and no matter how many configs I try I can't get it to work...

I'd really appreciate any help anyone can give me!!!

Here is the default nginx.conf from 'etc/nginx/': http://pastie.org/3825890

This is my server config file: http://pastie.org/3825903 and I have a rule that returns a 404 error code if Mozilla is the user agent (line 30) which is included with each server config block with this code: include /etc/nginx/server_config.conf;

I've looked up loads of forum posts for various nginx config and nothing makes nginx display my custom 404 error page...

If anyone can shed any light on this I would really appreciate it!!!!
Re: Nginx Custom 404 Custom Error Not Displaying [HELP]
April 21, 2012 06:58PM
Hi there.
I just saw You're question and needed to get a username in order to answer (I'm new to Nginx)

Have You tried to put this in Your server section ?


error_page 404 /404.html; ## or whatever You name it
location = /404.html {
root /usr/share/nginx/html; ## or whereever You put it - will not be needed if 404.html is where index.html is placed
}


This works for me and will do until I get more familiar with all the settings
Re: Nginx Custom 404 Custom Error Not Displaying [HELP]
April 21, 2012 09:27PM
Hey solo, thnx for the reply!

Yeah, the main bloxk has the root specifed for error page requests: (http://pastie.org/3825903)

location ~ ^/(403|404|413|50x).html
{
root /etc/nginx/error_pages;
allow all;
}

It's never been applied though!!!!!!!!!!!!!!!
Re: Nginx Custom 404 Custom Error Not Displaying [HELP]
April 22, 2012 09:22AM
I'm not sure what You mean but I get it that it still does not work ?

I would start out easy without all the ~^'s and so on because if anything can garble up things it's those settings ;-) :

WITHIN the SERVER section :

error_page 403 /403.html; ## need to tell which error You want to catch and what to do (show 403.html)
location = /403.html
{
/etc/nginx/error_pages;
}

error_page 404 /404.html
location = /404.html
{
......
}

and as an example

error_page 500 502 503 504 /50x.html;
location = /50x.html
{
root /etc/nginx/error_pages;
}


and make sure You have a 403.html and a 404.html and a 50x.html page in /etc/nginx/error_pages.

When this works You can start all the concatenating of stuff - then You know where to look if something does not work as expected.

Cheers,
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 156
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready