nginx/0.8.6 Configuration 404 Error page

Source: Internet
Author: User
Tags php tutorial

nginx/0.8.6 Configuration 404 Error page


nginx/0.8.6

Why do you want to customize 404 pages

When I encountered the 404 error page above, I thought that 99% (without investigation, estimated data) would turn off the page and the user would be quietly lost. If you can have a beautiful page at this time to guide users to where he wants to go, it is inevitable to retain users. Therefore, each site should customize its own 404 pages.

How to customize 404 pages under Nginx

IIS and Apache custom 404 Page Experience Introduction article has been very much, Nginx is still relatively few, coincidentally my several servers are nginx, in order to solve their own problems specifically for this in-depth study. The results show that it is feasible and simple to configure a custom 404 page under Nginx, with just the following steps:

1. Create your own 404.html page

2. Change nginx.conf join in the HTTP definition area:

Fastcgi_intercept_errors on;

3. Change nginx.conf to join in the server area:

Error_page 404 =/404.html

4. Test nginx.conf Correctness:

/opt/nginx/sbin/nginx–t

If correct, the following information should be displayed:

The configuration file/opt/nginx/conf/nginx.conf syntax is OK
Configuration file/opt/nginx/conf/nginx.conf test is successful

5. Restart Nginx

Kill-hup ' Cat/opt/nginx/nginx.pid '

Configuration file instance:

......

http
{
Include Mime.types;
Default_type Application/octet-stream;

CharSet gb2312;
Server_names_hash_bucket_size 128;
Client_header_buffer_size 32k;
Large_client_header_buffers 4 32k;
Client_max_body_size 8m;
Sendfile on;
Tcp_nopush on;

Keepalive_timeout 60;

Tcp_nodelay on;

Fastcgi_connect_timeout 300;
Fastcgi_send_timeout 300;
Fastcgi_read_timeout 300;
Fastcgi_buffer_size 64k;
Fastcgi_buffers 4 64k;
Fastcgi_busy_buffers_size 128k;
Fastcgi_temp_file_write_size 128k;
Fastcgi_intercept_errors on;

gzip on;
Gzip_min_length 1k;
Gzip_buffers 4 16k;
Gzip_http_version 1.0;
Gzip_comp_level 2;
Gzip_types text/plain application/x-Web page Special effects text/css tutorial Application/xml;
Gzip_vary on;

#limit_zone crawler $binary _remote_addr 10m;

  #65的配置信息
      server
{
   listen    & nbsp;  80;
   server_name  www.65.la 65.la *.65.la;
   index index.html index.htm index.php tutorial;
   root /opt/www/65;
   Location ~. *. (PHP|PHP5)? $
   {     
     #fastcgi_pass   UNIX :/tmp/php-cgi.sock;
     fastcgi_pass  127.0.0.1:9000;
     Fastcgi_index index.php;
     include fcgi.conf;
  }
   error_page  404 =/404.html;

Errors such as #502 can be configured in the same way.
Error_page 502 503 504 =/50x.html;
Ocation =/50x.html {
root HTML;
}
Log_format ' $remote _addr– $remote _user [$time _local] "$request"
' $status $body _bytes_sent ' $http _referer '
' $http _user_agent ' $http _x_forwarded_for ';
Access_log/opt/nginx/logs/65.log 65;
}

......

Note:

1. You must add: fastcgi_intercept_errors on; If this option is not set, even if the 404.html is created and the Error_page is configured, there is no effect.

Fastcgi_intercept_errors
Syntax: Fastcgi_intercept_errors on|off

Default: Fastcgi_intercept_errors off

Add Location: HTTP, server, location

By default, Nginx does not support custom 404 error pages, and only this instruction is set to On,nginx to support the redirection of 404 errors. It is important to note that the Fastcgi_intercept_errors On,nginx is not set to redirect the 404 error. In Nginx, the 404 error Redirection takes effect on the premise that fastcgi_intercept_errors on is set and the Error_page option (including syntax and corresponding 404 pages) is correctly set to 2. Not for the sake of convenience or improve the weight of the home page to specify 404 error pages, and do not use other methods to jump to the home page.

3. A custom 404 page must be greater than 512 bytes, otherwise the IE default 404 page may appear. For example, imagine a custom 404.html with a size of 11 bytes (content: 404 error). The following two non-existent addresses are accessed:

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.