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