设置Nginx允许上传文件的大小的代码详解

2024-03-04 0 917
目录
  • 1、Nginx官方文档说明:
  • 2、设置参数
    • 1)、在 server 模块中设置
    • 2)、在 http 模块中设置

1、Nginx官方文档说明:

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.

client_max_body_size 用来修改允许客户端上传文件的大小。默认为1m,如果设置为0,表示上传文件大小不受限制。

可以在以下模块设置: http, server, location

client_max_body_size 10m;

2、设置参数

1)、在 server 模块中设置

server {
listen 80;
server_name localhost;
#charset koi8-r;

# client_max_body_size 用来修改允许客户端上传文件的大小。默认为1m,如果设置为0,表示上传文件大小不受限制。
# 可以在以下模块设置: http, server, location
client_max_body_size 10m;

# 访问 / 网站跟目录返回的内容
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}


}

2)、在 http 模块中设置

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

log_format main \’$remote_addr – $remote_user [$time_local] \”$request\” \’
\’$status $body_bytes_sent \”$http_referer\” \’
\’\”$http_user_agent\” \”$http_x_forwarded_for\”\’;
access_log /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;

# 是否开启压缩功能
#gzip on;

# client_max_body_size 用来修改允许客户端上传文件的大小。默认为1m,如果设置为0,表示上传文件大小不受限制。
# 可以在以下模块设置: http, server, location
client_max_body_size 10m;

# 引用配置文件
include /etc/nginx/conf.d/*.conf;
}

以上就是设置Nginx允许上传文件的大小的方法详解的详细内容,更多关于设置Nginx上传文件的大小的资料请关注悠久资源其它相关文章!

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

悠久资源 Nginx服务器 设置Nginx允许上传文件的大小的代码详解 https://www.u-9.cn/server/nginx/182914.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务