What is 404 pageIf something happens to the site, or if the user tries to access a page that does not exist, the server returns an error message with a code of 404, and the corresponding page is 404 pages. 404 The default content of the page is related to the specific server. If the background is using Nginx server, then the content of 404 pages is: 404 Not foundnginx/0.8.6Why customize 404 pagesWhen I visited the above 404 error page, I think 99% (without investigation, estimate data) users will turn off the page, the user so quietly lost. If you can have a beautiful page at this time to guide the user to the place where he wants to go must be able to retain users. Therefore, each site should customize its own 404 pages.How to customize 404 pages under NginxIIS and Apache under the custom 404 page Experience Introduction article has been very much, Nginx is still relatively small, coincidentally, I have a few servers are nginx, in order to solve their own problems specifically to this in-depth study. The results show that it is possible to configure a custom 404 page in Nginx, and it is very simple, just the following steps:1.Create your own 404.html page2.Change nginx.conf in the HTTP definition area: fastcgi_intercept_errors on;3.Change nginx.conf in Server zone join: error_page 404 =/404.html4.Test nginx.conf correctness:/opt/nginx/sbin/nginx–t should display the following information correctly: The configuration file/opt/nginx/conf/nginx.conf syntax is OK Configuration file/opt/nginx/conf/nginx.conf test is successfulkill-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-javascript text/css application/xml;
- Gzip_vary on;
- #limit_zone crawler $binary _remote_addr 10m;
Copy Code #65的配置信息
- Server
- {
- Listen 80;
- server_name www.65.la 65.la *.65.la;
- Index index.html index.htm index.php;
- 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;
Copy Code 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;
- }
Copy Code ......Precautions :1. Must be added: Fastcgi_intercept_errors on; If this option is not set, there is no effect even if 404.html is created and Error_page is configured. 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 404 error redirection. It is important to note that it is not said that setting the Fastcgi_intercept_errors On,nginx will redirect the 404 error. In Nginx, 404 error redirection takes effect if fastcgi_intercept_errors on is set and the Error_page option (including syntax and corresponding 404 pages) is set correctly 2. Do not for the sake of convenience or improve the purpose of home page weight to designate the homepage as 404 error page, do not use other methods to jump to the homepage. 3. The custom 404 page must be greater than 512 bytes, otherwise the IE default 404 page may appear. For example, suppose you have customized 404.html with a size of only 11 bytes (content: 404 error). Use the following two non-existent addresses to access: Ask a question, where do you put the 404 pages you created? I haven't tried it yet. @5169.info You can put it anywhere, pay attention to changing the line configuration. Error_page 404 =/404.html;
@5169.info You can put it anywhere, pay attention to changing the line configuration. Error_page 404 =/404.html; in other words, each sub-station copies a copy of the 404 file, can this Error_page 404 =.. /404.html; Just do a set of 404 and put it under Htdocs. At present, there are no trackbacks and pingbacks in this paper. Note: Reviewers are allowed to use' @user: 'To inform other reviewers of their own comments. For example, if ABC is one of the reviewers of this article, using ' @ABC excluding single quotes ' will automatically send your comments to ABC. User must match the reviewer name, case sensitive start.jpg (412.91 KB, download times:) Download attachments 404 2015-7-19 14:55 Upload
|