Home > Operation and Maintenance > Nginx > How to configure nginx 404

How to configure nginx 404

(*-*)浩
Release: 2019-06-18 11:09:50
Original
10345 people have browsed it

404 error is an error that is prone to occur when accessing WWW websites. The most common error message: 404 NOT FOUND.

How to configure nginx 404

# The settings of the 404 error page have a great impact on the SEO of the website. Improper settings, such as directly redirecting to the homepage, etc., will be demoted and plucked by search engines. The purpose of the 404 page should be to tell the user that the page you requested does not exist, and to guide the user to browse other pages of the website instead of closing the window and leaving. Search engines use HTTP status codes to identify the status of web pages. When a search engine obtains a bad link, the website should return a 404 status code to tell the search engine to abandon indexing the link. If a 200 or 302 status code is returned, the search engine will index the link, resulting in a large number of different links pointing to the same web page content. As a result, search engines’ trust in the website has been significantly reduced.

The following is a tutorial on setting up Nginx 404 error page with LNMP:

1. vi /usr/local/nginx/conf/nginx.conf Edit the Nginx configuration file , add the following code in the http section:

fastcgi_intercept_errors on;
Copy after login

2. Edit the website configuration file, such as this site: vi /usr/local/nginx/conf/vhost/onelone.com.conf, add it in the server section The following code

error_page 404 = /404.html;
Copy after login

Note: Some netizens tested that the upstream code needs to remove the equal sign to return the correct 404 status, so students are asked to test whether they need to remove the equal sign.

3. Test whether the configuration file is correct: /usr/local/nginx/sbin/nginx -t, return the following code to pass:

the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
configuration file /usr/local/nginx/conf/nginx.conf test is successful
Copy after login

4. Restart LNMP to take effect:

/root/lnmp restart 。
Copy after login

5. Notes on making 404 error pages:

Do not redirect 404 errors to the homepage of the website, otherwise it may cause the homepage to be demoted or disappear in search engines.

Do not use absolute URLs. If you use absolute URLs, the status code returned is 302 200, which will generate a large number of duplicate web pages.

404 page setting is completed, be sure to check whether it is correct. The http header information returned must be a 404 status. This can be checked through the server header information inspection tool.

Do not automatically jump to the 404 page, let the user decide where to go.

The custom 404 page must be larger than 512 bytes, otherwise the IE default 404 page may appear.

For more Nginx related technical articles, please visit the Nginx usage tutorial column to learn!

The above is the detailed content of How to configure nginx 404. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template