Home Operation and Maintenance Nginx How to configure nginx 404

How to configure nginx 404

Jun 11, 2019 am 10:16 AM
nginx

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!

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to allow external network access to tomcat server How to allow external network access to tomcat server Apr 21, 2024 am 07:22 AM

How to allow external network access to tomcat server

What are the nginx start and stop commands? What are the nginx start and stop commands? Apr 02, 2024 pm 08:45 PM

What are the nginx start and stop commands?

How to run thinkphp How to run thinkphp Apr 09, 2024 pm 05:39 PM

How to run thinkphp

What are the differences between tomcat and nginx What are the differences between tomcat and nginx Dec 27, 2023 pm 05:07 PM

What are the differences between tomcat and nginx

How to register phpmyadmin How to register phpmyadmin Apr 07, 2024 pm 02:45 PM

How to register phpmyadmin

Welcome to nginx!How to solve it? Welcome to nginx!How to solve it? Apr 17, 2024 am 05:12 AM

Welcome to nginx!How to solve it?

How to deploy nodejs project to server How to deploy nodejs project to server Apr 21, 2024 am 04:40 AM

How to deploy nodejs project to server

How to solve the problem of nginx when accessing the website How to solve the problem of nginx when accessing the website Apr 02, 2024 pm 08:39 PM

How to solve the problem of nginx when accessing the website

See all articles