net::ERR_CONTENT_LENGTH_MISMATCH 206 (Partial Content) 报错

1. Problem description

Recently, the on-site implementation personnel reported that there is a function that cannot be used normally. F12 checks the console of the browser and prompts an error of net::ERR_CONTENT_LENGTH_MISMATCH 206 (Partial Content).

The HTTP status code 206 means "Partial Content", which means that the server successfully processed some of the client's requests. Usually, this status code is returned when the client requests some resources through the HTTP Range header. If the server does not support range requests, the following reasons may cause this problem

Two, the cause of the problem

  1. The server's disk is full, causing the application to fail to work normally
  2. There is no permission when nginx cache file is read (Permission denied)
  3. The proxy cache area of ​​nginx is too small

3. Problem analysis and solution

1. The disk of the server is full, causing the application to fail to work normally

 (1)df -h 命令查看磁盘的使用情况
 (2)进入根路径,使用 du -sh * 命令查看哪个文件夹占用多
 (3)发现usr文件夹占用最多,进入usr文件夹,再次执行 du -sh * 查询usr文件夹下占用大的文件夹,以此类推
 (4)最终查到占用空间最大的文件,根据自己的实际情况进行删除无用的文件
df -h

places - view disk usage insert image here description find
Enter the root path, use the du -sh * command to see which folder takes up the most Insert picture description here
insert image description here
insert image description here

2. There is no permission when reading the nginx cache file (Permission denied)

The network addresses of css and js in the hearer can be opened separately, so the simplest address errors are ruled out. The front-end project is proxied by nginx, so you can view the nginx log, enter ${NGINX_HOME}\logs, view error.log, and get the following information:

[crit] 275197#0: *1543 open() “/usr/local/nginx/proxy_temp/4/30/0000000304” failed (13: Permission denied) while reading upstream

(1) What is the proxy_temp folder and what is it used for

Nginx improves the performance of its reverse proxy server with a proxy cache. Proxy cache is a technology that caches the response of the reverse proxy server on the local disk, which can relieve the pressure on the upstream server and improve the access speed of the client.

In order to implement the proxy cache function, Nginx needs to write the data responded by the proxy server to a temporary file on the local disk. These temporary files are stored in the proxy_temp folder for easy management and maintenance by Nginx.

The temporary files in the proxy_temp folder are automatically managed by Nginx, and when the cache is no longer needed, Nginx will automatically delete them to avoid taking up too much disk space.

(2) Enter the /usr/local/nginx/proxy_temp folder, check folder permissions and nginx users

It is found that the owner of the proxy_temp folder is the nobody user, and nginx is the root userView folder permissions insert image description here

Modify the nginx configuration file and declare the user

1. Open the Nginx configuration file. By default, the Nginx configuration file is located at /etc/nginx/nginx.conf.

2. Find the "worker_processes" line in the configuration file, which sets the number of worker processes. Add the following below this line:

 user yourusername;

where yourusername is the username you want to use to run Nginx.

3. Save and close the file.

4. Check the Nginx configuration file for syntax errors. The following commands can be used:

   nginx -t

If the configuration file has no syntax errors, it will output "nginx: configuration file /etc/nginx/nginx.conf test is successful".

5. Restart the Nginx service for the configuration changes to take effect. The following commands can be used:

sudo systemctl restart nginx

Now, Nginx will run with the username you specified.

3. The proxy cache area of ​​nginx is too small

Add the following three lines of code to the http configuration of the nginx.conf.js file, then save and restart nginx

proxy_buffer_size 128k;
proxy_buffers   32 128k;
proxy_busy_buffers_size 128k;

Specific analysis:
(1) proxy_buffer_size: This command sets the size of a single proxy buffer. It is used to specify the maximum number of bytes that Nginx stores in the buffer before sending a response to the client. By default, this value is 4K.
For example, if you set proxy_buffer_size to 128k, when Nginx proxy receives a response from an upstream server, it will use a buffer of up to 128K to store the response before sending it to the client.

(2) proxy_buffers: This command sets the number and size of proxy buffers. A proxy buffer is an area of ​​memory used to store responses received from upstream servers. The proxy_buffers directive consists of two parameters: the number of buffers and the size of each buffer. By default, Nginx uses 8 buffers, each with a size of 4K.
For example, if you set proxy_buffers to 32 128k, Nginx will use 32 buffers, each of size 128K.

(3) proxy_busy_buffers_size: This directive sets the maximum number of bytes that can be used to store responses in the proxy buffer. When Nginx is sending a response to the client, it will take the buffer from the proxy buffer. If the buffer size is less than proxy_busy_buffers_size, Nginx will try to get more responses from the upstream server and store them in another buffer middle.
For example, if you set proxy_busy_buffers_size to 128k, when Nginx proxy uses buffers to send responses to clients, it will take buffers from the proxy buffers, and only if the buffer size is less than 128K, Nginx will send responses from the upstream server Get more responses.

It should be noted that these proxy buffer configuration items can be adjusted according to specific conditions to achieve the best performance and resource utilization.

Guess you like

Origin blog.csdn.net/qq_35432904/article/details/130363226