NGINX Configuration 404 Error page turn

Source: Internet
Author: User
Tags nginx server
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:......
  1. http
  2. {
  3. Include Mime.types;
  4. Default_type Application/octet-stream;
  5. CharSet gb2312;
  6. Server_names_hash_bucket_size 128;
  7. Client_header_buffer_size 32k;
  8. Large_client_header_buffers 4 32k;
  9. Client_max_body_size 8m;
  10. Sendfile on;
  11. Tcp_nopush on;
  12. Keepalive_timeout 60;
  13. Tcp_nodelay on;
  14. Fastcgi_connect_timeout 300;
  15. Fastcgi_send_timeout 300;
  16. Fastcgi_read_timeout 300;
  17. Fastcgi_buffer_size 64k;
  18. Fastcgi_buffers 4 64k;
  19. Fastcgi_busy_buffers_size 128k;
  20. Fastcgi_temp_file_write_size 128k;
  21. Fastcgi_intercept_errors on;
  22. gzip on;
  23. Gzip_min_length 1k;
  24. Gzip_buffers 4 16k;
  25. Gzip_http_version 1.0;
  26. Gzip_comp_level 2;
  27. Gzip_types text/plain application/x-javascript text/css application/xml;
  28. Gzip_vary on;
  29. #limit_zone crawler $binary _remote_addr 10m;
Copy Code
#65的配置信息
    1. Server
    2. {
    3. Listen 80;
    4. server_name www.65.la 65.la *.65.la;
    5. Index index.html index.htm index.php;
    6. ROOT/OPT/WWW/65;
    7. Location ~. *\. (PHP|PHP5)? $
    8. {
    9. #fastcgi_pass Unix:/tmp/php-cgi.sock;
    10. Fastcgi_pass 127.0.0.1:9000;
    11. Fastcgi_index index.php;
    12. Include fcgi.conf;
    13. }
    14. Error_page 404 =/404.html;
Copy Code
Errors such as #502 can be configured in the same way.
    1. Error_page 502 503 504 =/50x.html;
    2. Ocation =/50x.html {
    3. root HTML;
    4. }
    5. Log_format ' $remote _addr– $remote _user [$time _local] "$request"
    6. ' $status $body _bytes_sent ' $http _referer '
    7. ' "$http _user_agent" $http _x_forwarded_for ';
    8. Access_log/opt/nginx/logs/65.log 65;
    9. }
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


  • 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.