The custom 404 page with incorrect nginx settings jumps to 500

Source: Internet
Author: User

The website written five years ago was the error page written under apache. After nginx was changed, the 404 page directly jumped to the internal error of the 500 server.


You only need to configure

Specify try_files.

Debian, in/etc/nginx/site-available/default, location/

Server {

</pre><pre name="code" class="plain">location / {        <span style="white-space:pre"></span>try_files $uri $uri/ /error/404.php?c=404 =404;    <span style="white-space:pre"></span>}
<pre name="code" class="plain"><span style="white-space:pre"></span>error_page 403 /error/403.php;<span style="white-space:pre"></span>error_page 404 /error/404.php;<span style="white-space:pre"></span>error_page 500 501 502 503 504 /error/500.php;

} 

Then reload nginx.

Reference http://wiki.nginx.org/HttpCoreModule#try_files

Note: I put the page under the error folder under the website directory. For example, if the website is placed on the/var/www/error page, it is in/var/www/error/403.php...

The test is very simple. 403 does not have the permission, for example, your website directory css directory, image directory or something. 404 does not exist. You can just enter an address. 500 is on the server, here I will stop php-fpm for testing. the effect is as follows:







Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.