設(shè)置Nginx允許上傳文件的大小的代碼詳解
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 用來修改允許客戶端上傳文件的大小。默認(rèn)為1m,如果設(shè)置為0,表示上傳文件大小不受限制。
可以在以下模塊設(shè)置: http, server, location
client_max_body_size 10m;
2、設(shè)置參數(shù)
1)、在 server 模塊中設(shè)置
server {
listen 80;
server_name localhost;
#charset koi8-r;
# client_max_body_size 用來修改允許客戶端上傳文件的大小。默認(rèn)為1m,如果設(shè)置為0,表示上傳文件大小不受限制。
# 可以在以下模塊設(shè)置: http, server, location
client_max_body_size 10m;
# 訪問 / 網(wǎng)站跟目錄返回的內(nèi)容
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
...
}2)、在 http 模塊中設(shè)置
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 用來修改允許客戶端上傳文件的大小。默認(rèn)為1m,如果設(shè)置為0,表示上傳文件大小不受限制。
# 可以在以下模塊設(shè)置: http, server, location
client_max_body_size 10m;
# 引用配置文件
include /etc/nginx/conf.d/*.conf;
}以上就是設(shè)置Nginx允許上傳文件的大小的方法詳解的詳細(xì)內(nèi)容,更多關(guān)于設(shè)置Nginx上傳文件的大小的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Nginx中add_header和proxy_set_header的區(qū)別及說明
這篇文章主要介紹了Nginx中add_header和proxy_set_header的區(qū)別及說明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-06-06
基于Nginx的衍生版服務(wù)器Tengine簡(jiǎn)介
這篇文章主要介紹了基于Nginx的衍生版服務(wù)器Tengine簡(jiǎn)介,本文講解了Nginx的特性、Tengine的特性、架構(gòu)和擴(kuò)展性等內(nèi)容,需要的朋友可以參考下2015-03-03
Nginx與Lua灰度發(fā)布的實(shí)現(xiàn)
這篇文章主要介紹了Nginx與Lua灰度發(fā)布的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-03-03
Nginx Lua 根據(jù)參數(shù)請(qǐng)求轉(zhuǎn)發(fā)的實(shí)現(xiàn)
本文介紹了如何使用Nginx和Lua腳本實(shí)現(xiàn)基于參數(shù)的請(qǐng)求轉(zhuǎn)發(fā),文章詳細(xì)說明了配置方法,并提供了示例代碼,幫助讀者理解如何通過NginxLua模塊根據(jù)請(qǐng)求參數(shù)將流量轉(zhuǎn)發(fā)到不同后端服務(wù),這種方法有助于實(shí)現(xiàn)靈活的負(fù)載均衡和動(dòng)態(tài)內(nèi)容處理2022-05-05
Nginx如何實(shí)現(xiàn)對(duì)城市以及指定IP的訪問限制
本文介紹了如何使用Nginx代理MySQL連接并限制可訪問IP,以及如何通過第三方模塊ngx_http_geoip2_module實(shí)現(xiàn)基于國(guó)家/城市訪問限制2025-03-03
在Nginx服務(wù)器中配置針對(duì)TCP的負(fù)載均衡的方法
這篇文章主要介紹了在Nginx服務(wù)器中配置針對(duì)TCP的負(fù)載均衡的方法,另外還介紹了TCP負(fù)載均衡的執(zhí)行原理,需要的朋友可以參考下2015-12-12

