Error: Request failed with status code 413

Error graph

 

generate scene

1. Set up a document server to store pictures and files. Easy to display

2. It is used in the local environment, and there is no problem during the test. But when I used it online, I found that only 5k words can be uploaded successfully

3. HTTP 413 error, 413 is the request body is too large to report an error.

solution

1. Add a configuration file under http in the nginx/conf/nginx file

guess

1. Axios has this configuration when using the document server in the local environment. When it is online, Nginx is forwarding, and 413 may fail, so it needs to be configured in Nginx

code show as below

worker_processes  1;
events {
    worker_connections  1024;
}
​
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    
    #解决请求体过大配置
    #允许客户端请求的最大单文件字节数
    client_max_body_size 15m; 
    #缓冲区代理缓冲用户端请求的最大字节数
    client_body_buffer_size 128k;
​
    server {
        listen       80;
        #定义服务器的默认网站根目录位置
        server_name  localhost;
        location / {
            root   html/dist;
            index  index.html index.htm;
            try_files $uri $uri/ /index.html; #解决页面刷新404问题
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

Summarize:

After this process, I believe you also have a preliminary deep impression on the online file upload request 413, but the situation we encounter in actual development must be different, so we must understand its principle, and it will never change. Its case. Come on, hit the workers!

Please point out any deficiencies, thank you -- Fengguowuhen

Guess you like

Origin blog.csdn.net/weixin_53579656/article/details/130936208