Resolve the "soft 404" error when Nginx sets the correct 404 custom page

Source: Internet
Author: User
One day after VPS was changed, a large number of "soft 404" errors were found in the Google administrator tool console, after searching for some information, we found that the incorrect method for configuring the 404 page under Nginx resulted in an error. here we record the correct 404 page configuration method under Nginx. 404 is a code that indicates "PageNotFound cannot be found on the page". Google's statement about "soft 404" is: Instead

One day after VPS was changed, a large number of "soft 404" errors were found in the Google administrator tool console, after searching for some information, we found that the incorrect method for configuring the 404 page under Nginx resulted in an error. here we record the correct 404 page configuration method under Nginx.

404 is a code that indicates "Page Not Found" (Page Not Found). Google's statement about "soft 404" is:

Instead of returning a 404 response code for a non-existent URL, websites that serve "soft 404 s" return a 200 response code.

That is to say, for those URLs that do Not exist, the server does Not return the 404 (Page Not Found) code, but returns the 200 (OK) code, which is Not normal.

Later, I saw this paragraph in other search results.

Soft 404 s can occur as a result of configuration errors when an Error Document 404 is specified as an absolute path rather than a relative path.

After reading it, I suddenly realized that my 404 custom page has images and CSS, and the image and CSS are both in relative paths (eg. /xxx) is written on the page, so in order to make the whole site see the pictures on the 404 page, I define the 404 page in Nginx as an absolute path (eg. because the page is treated as an external page, 200 code is returned, resulting in a "soft 404" error.

If you know the error, it's easy. Define the path of the 404 page as a relative path. for images and CSS, you only need to use the absolute path on the page.

Correct 404 page definition method in Nginx:

1. VIM edits the Nginx configuration file and uses vhosts to modify it separately. nginx. conf is useless.

vim  /usr/local/nginx/conf/nginx.conf

Or

vim  /usr/local/nginx/conf/vhosts/slyar.com.nginx.conf

2. specify the 404 page in the relative path

server { #error_page 404 http://www.slyar.com/404.html error_page  404 /404.html; }

3. save and exit wq and reload Nginx

/usr/local/nginx/sbin/nginx -s reload

4. check the page that does not exist and check whether 404 is returned.

Curl-I http://www.slyar.com/slyar

HTTP/1.1 404 Not Found
Server: nginx/1.0.15
Date: Mon, 27 Aug 2012 08:13:56 GMT
Content-Type: text/html
Content-Length: 2110
Connection: keep-alive

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.