-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
我还真没去深究过,那测试试试吧
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.
搭环境是不可能搭环境的
docker pull docker.io/webdevops/php-nginx:latest
mkdir app
touch app/index.php
docker run -it -d --name nginx_test -p 50000:80 -v /root/sanXian/php-nginx-test/app:/app:rw -v /root/sanXian/php-nginx-test/vhost.conf:/opt/docker/etc/nginx/vhost.conf webdevops/php-nginx
docker cp nginx_test:/opt/docker/etc/nginx/vhost.conf ./
好了, 环境有了, 干活
nginx -s reload
期间报了一次错
nginx: [emerg] "client_max_body_size" directive is duplicate in /opt/docker/etc/nginx/vhost.common.d/10-general.conf:1
检查
# cat /opt/docker/etc/nginx/vhost.common.d/10-general.conf
client_max_body_size 50m;
# cat /etc/nginx/nginx.conf | grep -Ev "^\s*?#|^$"
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
access_log /docker.stdout ;
error_log /docker.stderr ;
gzip on;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
# cat /etc/nginx/conf.d/10-docker.conf
include /opt/docker/etc/nginx/global.conf;
include /opt/docker/etc/nginx/php.conf;
include /opt/docker/etc/nginx/conf.d/*.conf;
include /opt/docker/etc/nginx/vhost.conf;
# cat /opt/docker/etc/nginx/vhost.conf
server {
listen 80 default_server;
server_name _ *.vm docker;
root "/app";
index index.php;
client_max_body_size 1m;
include /opt/docker/etc/nginx/vhost.common.d/*.conf;
}
server {
listen 443 default_server;
server_name _ *.vm docker;
root "/app";
index index.php;
include /opt/docker/etc/nginx/vhost.common.d/*.conf;
include /opt/docker/etc/nginx/vhost.ssl.conf;
}
# rm -f /opt/docker/etc/nginx/vhost.common.d/10-general.conf
# nginx -s reload
这说明了啥?这只说明了client_max_body_size不能在server context里面重复定义,能不能跨context定义达到覆写效果呢,实测在http context定义了client_max_body_size 后再在server context定义也是可以的
制造文件测试
dd if=/dev/zero of=./zero.img bs=1MiB count=$(expr 1024 \* 1000 - 200 )
dd if=/dev/zero of=./zero.img bs=1 count=$(expr 1024 \* 1024 - 200 )
dd if=/dev/zero of=./zero.img bs=1 count=$(expr 1024 \* 1024 - 200 + 1 )
(别问我200这个数值怎么算出来的,我随便猜的[too vegetable])
结论
size 里面如果单位是m, 那是MiB
CrabAss