简体   繁体   中英

Cannot Upload file bigger then 1.7mb 400 bad request Nginx php-fpm linux

I am trying to upload mp4 files bigger than 50 MB of size. I deployed from the docker image of PHP-fpm7.1 with Nginx along the following configurations given below. This is my Nginx configurations file.

I am receiving 400 on upload files bigger than 1.5 MB. but I want 50 MB of upload support. Does any one know if any thing is wrong in my configurations that make this problem?

user  root;
worker_processes  2;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

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


    real_ip_header X-Forwarded-For;
    set_real_ip_from 0.0.0.0/0;

    log_format main '$remote_addr - $remote_user [$time_local] '
                       '"$request" $status $bytes_sent '
                       '"$http_referer" "$http_user_agent"';
                       
    access_log  /var/log/nginx/access.log  main;
    error_log /var/log/nginx/error.log;

    ## Cache
    ##open_file_cache max=1000 inactive=24h;
    ##open_file_cache_valid 24h;
    ##open_file_cache_min_uses 2;
    ##open_file_cache_errors on;

    ## Timeouts
    client_header_timeout 15;
    client_body_timeout 15;
    send_timeout 15;
    keepalive_timeout 0;

    ## Size limits
    # client_max_body_size 100M;
    client_header_buffer_size 32k;
    client_body_buffer_size 128k;
    large_client_header_buffers 64 8k;

    ## General
    types_hash_max_size 2048;
    server_names_hash_bucket_size 64;
    ignore_invalid_headers on;
    limit_conn_zone $binary_remote_addr zone=addr:10m;
    recursive_error_pages on;
    reset_timedout_connection on;
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    server_tokens off;
    server_name_in_redirect off;
    keepalive_requests 0;
    client_max_body_size 1024m;

    ## Compression
    gzip on;
    gzip_static on;
    gzip_comp_level 6;
    gzip_disable "msie6";
    gzip_buffers 16 8k;
    gzip_vary on;
    gzip_proxied any;
    gzip_min_length 256;
    gzip_http_version 1.1;
    gzip_types text/css text/javascript text/xml text/plain application/javascript application/x-javascript application/json application/xml application/rss+xml image/svg+xml;
    output_buffers 10 128k;
    postpone_output 1500;

    ## Fastcgi Caching
    #fastcgi_cache_path /var/cache/nginx/fastcgi_tmp levels=1:2
    #keys_zone=CZONE:15m inactive=60m;
    #fastcgi_cache_key "$scheme$request_method$host$request_uri";
    #fastcgi_cache_use_stale error timeout invalid_header http_500;

    server {
        listen 80;
        root /app/src/public; 
        index index.html index.htm index.php;

        error_page 500 501 502 503 504 505 506 507 508 509 510 511 /error/bad_request;
        error_page 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 420 422 423 424 426 428 429 431 444 449 450 451 /error/not_found;

        ## Rewrite rules
        location / {
            try_files $uri $uri/ /index.php?$args;
        }
        
        location ^~ /relay {
            allow 50.17.201.90;
            allow 52.77.175.201;
            deny all; 
            try_files $uri $uri/ /index.php?$args;
            error_page 403 = @kick_out;
        }

        location @kick_out {
            rewrite ^(.*) https://$server_name/error/not_found;
        }

        ## Deny access to hidden files
        location ~ /\. {
            deny all;
        }

        ## No log for known files
        location ~* ^.+\.(js|css|swf|xml|ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|mid|midi|wav|bmp)$ {
            access_log off; log_not_found off; expires 30d;
        }
        location = /favicon.ico {
            access_log off; log_not_found off; expires 30d;
        }
        location = /robots.txt {
            allow all; access_log off; log_not_found off; expires 30d;
        }
        location = /health {
            return 200; access_log off; log_not_found off; expires 30d;
        }
        
        ## Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        location ~ \.php$ { 
            try_files $uri = 404;
            fastcgi_pass 127.0.0.1:9000; 
            fastcgi_index index.php; 
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_connect_timeout 60;
            fastcgi_send_timeout 90;
            fastcgi_read_timeout 90;
            fastcgi_buffer_size 512k;
            fastcgi_buffers 64 512k;
            fastcgi_cache_valid any 1h;
            include fastcgi_params; 
        }

    }

}

And my php.ini file is

[www]
user = root
group = root
listen = 127.0.0.1:9000
listen.allowed_clients = 127.0.0.1
pm = dynamic
pm.max_children = 100
pm.start_servers = 10
pm.min_spare_servers = 10
pm.max_spare_servers = 20
request_terminate_timeout = 120
slowlog = /var/log/nginx/error.log
expose_php = Off
error_reporting = E_ALL & ~E_NOTICE
display_errors = 1
upload_max_filesize = 100M
post_max_size = 100M
memory_limit = 512M

When I upload file up to 1.5 MB it works fine and when I try bigger files it gives me 400 bad server request

The correct setting is

client_max_body_size <size here>M;

Also, its a good idea not to set it for the whole server - keep the higher setting within the required location block.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM