Nginx常见报错整理

文章目录

前言

本篇博客是对Nginx常见报错整理。

所有博客文件目录索引:博客目录索引(持续更新)

出现问题

1、Nginx服务出现413 Request Entity Too Large的解决办法

原因分析:

查看Nginx 关于client_max_body_size的描述 http服务客户端最大上传默认设置为1M

Syntax: client_max_body_size size; Default: client_max_body_size 1m; Context: http, server, location

Sets the maximum allowed size of the client request body, specified in
the “Content-Length” request header field. If the size in a request
exceeds the configured value, the 413 (Request Entity Too Large) error
is returned to the client. Please be aware that browsers cannot
correctly display this error. Setting size to 0 disables checking of
client request body size.

解决办法:

修改nginx.conf配置文件,增加client_max_body_size大小。

http {
 	...
 	# set client body size to 50M #
    client_max_body_size 50m;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    ...
}

2、HTTP请求:Failed to load resource: the server responded with a status of 413 (Request Entity Too Large)

上传文件时出现:请求体过大无法上传

image-20220415152218042

解决方案:设置client_max_body_size 8M

设置位置:

可以选择在http{ }中设置:client_max_body_size 20m;
也可以选择在server{ }中设置:client_max_body_size 20m;
还可以选择在location{ }中设置:client_max_body_size 20m;
三者到区别是:http{} 中控制着所有nginx收到的请求。而报文大小限制设置在server{}中,则控制该server收到的请求报文大小,同理,如果配置在location中,则报文大小限制,只对匹配了location 路由规则的请求生效。

评论区请在客户端页面查看