Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Summary and Analysis methods of Common error codes in Nginx

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

403 error

403 is a very common error code, which generally means unauthorized access.

There are two possible reasons:

Nginx program users do not have permission to access web directory files

Nginx needs to access the directory, but the autoindex option is turned off

Repair method:

Grant Nginx program user permission to read web directory files

Set the autoindex directory to on

Location / path/to/website/folder {

...

Autoindex on

...}

413 error

Nginx returned a 413 error when uploading: "413 Request Entity Too Large", which is usually caused by the uploaded file size exceeding the Nginx configuration.

Repair method:

Add the client_max_body_size setting in Nginx.conf, which defaults to 1m, which can be increased to 8m to increase the file size limit

If you are running php, also check the php.ini, which is the same size as or slightly larger than the maximum of the following values in php.ini, so that there are no errors due to the inconsistent size of the submitted data.

Post_max_size = 8m

Upload_max_filesize = 2m

502 error

Nginx 502Bad Gateway means that the requested PHP-CGI has been executed, but the PHP-CGI process is terminated due to some reason (usually the problem of reading resources) that the execution is not finished. Generally speaking, Nginx 502 Bad Gateway is related to the setting of php-fpm.conf.

Repair method:

1. Check whether the FastCGI process has been started

Ps-aux | grep php-cgi

2. Check the operation of the Fastcgi process on the system

Except for the first case, an insufficient number of fastcgi processes, a long php execution time, or the death of a php-cgi process can also cause Nginx 502 errors.

Run the following command to determine whether it is close to FastCGI processes. If the number of fastcgi processes is close to the value set in the configuration file, the number of worker processes is set too little.

Netstat-anpo | grep "php-cgi" | wc-l

3. FastCGI execution time is too long.

Increase the following parameter values according to the actual situation

Fastcgi_connect_timeout 300

Fastcgi_send_timeout 300

Fastcgi_read_timeout 300

504 error

Nginx 504 Gateway Time-out means that the requested gateway is not requested, which simply means that there is no request for an executable PHP-CGI.

Nginx 504 Gateway Time-out is generally related to the setting of Nginx.conf.

The fact that the header is too large may be due to the fact that the response buffer of the Nginx default fastcgi process is too small, which will cause the fastcgi process to be suspended, and if your fastcgi service does not handle this hang well, it will most likely lead to 504 Gateway Time-out in the end.

The default buffer for fastcgi process response is 8K, and you can increase the following parameters:

Fastcgi_buffer_size 128k

Fastcgi_buffers 8 128k

Fastcgi_busy_buffers_size changed from 128K to 256k

Fastcgi_temp_file_write_size was changed from 128K to 256K.

In addition, it may also be a problem with php-cgi, and you need to modify the configuration of php.ini:

Change max_children from 10 to 30 to ensure that there are enough php-cgi processes to be used.

Change the request_terminate_timeout from 0 seconds to 60 seconds, which increases the timeout time for the php-cgi process to process scripts to 60 seconds, preventing the process from being suspended and improving utilization efficiency.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report