找到配置文件
Nginx的主配置文件通常是 nginx.conf,它可能位于 /etc/nginx/nginx.conf、/usr/local/nginx/conf/nginx.conf 等路径下。你也可以在 /etc/nginx/conf.d/ 或 /etc/nginx/sites-available/ 目录下找到针对特定站点的配置文件。
设置指令作用域client_max_body_size 指令可以放在 http、server 或 location 块中,其作用范围也随之不同。
全局设置(http块):对所有站点生效。
http {
client_max_body_size 10M;
# ... 其他配置 ...
}特定站点(server块):只对该虚拟主机生效。
server {
listen 80;
server_name example.com;
client_max_body_size 20M; # 此站点上限为20MB
# ... 其他配置 ...
}特定路径(location块):只对匹配的URL路径生效,非常适合为上传接口单独设置。
server {
listen 80;
server_name example.com;
location /upload {
client_max_body_size 50M; # 上传路径上限为50MB
# ... 其他上传相关配置 ...
}
}提示:如遇链接失效,请在评论区留言反馈