Unable to upload a big file to server behind nginx as a reverse proxy

15,512

In nginx.conf set the max body size.

client_max_body_size 20M;

Also GoTo /etc/php5/fpm/php.ini

; Maximum size of POST data that PHP will accept.

post_max_size = 100M

; Maximum allowed size for uploaded files.

upload_max_filesize = 100M

Share:
15,512

Related videos on Youtube

Mohsen Saberi
Author by

Mohsen Saberi

Updated on September 18, 2022

Comments

  • Mohsen Saberi
    Mohsen Saberi almost 2 years

    I use nginx as a reverse proxy. Behind it is coming apache hosing foo.com . In order to upload a big file, I set post_max_size = 20M and upload_max_filesize = 20M in php.ini . But I can't upload file with size bigger than 2MB. My nginx configuration is:

    server {
    listen 80;
    server_name  .foo.com;
    if ($http_host != "www.foo.com") {
        rewrite ^ http://www.foo.com$request_uri permanent;
    }
    access_log /var/log/nginx/foo.access.log;
    error_log /var/log/nginx/foo.error.log;
    
    index index.php index.html;
    
    location / {
        proxy_pass http://192.168.1.2:80/;
        include /etc/nginx/proxy_params;
        proxy_buffering off;
        chunked_transfer_encoding on;
       }
    }
    

    In addition I configured nginx.conf as following:

    http {
    ...
        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 600;
        client_max_body_size 200M;
        types_hash_max_size 2048;
        # server_tokens off;
    
        include fastcgi_params;
        fastcgi_read_timeout 600;
        proxy_connect_timeout       600;
        proxy_send_timeout          600;
        proxy_read_timeout          600;
        send_timeout                600;
    ...
    }
    

    Any ideas on how to solve the problem?

    • larowlan
      larowlan over 8 years
      What are you using to POST? Curl might be adding an Expect header
    • Mohsen Saberi
      Mohsen Saberi over 8 years
      I tested and used many browsers, like IE or Firefox. Neither of them got the true result.
    • kamihack
      kamihack almost 8 years
      @MohsenSaberi did you try increasing nginx and PHP logging to pinpoint the reason? Also, do you receive any kind of HTTP code when the connection is cut? You could use a proxy or sniffer to know exactly what the HTTP response looks when it cuts transmission
  • Mohsen Saberi
    Mohsen Saberi about 9 years
    These configurations are also set, but don't answer.
  • arundev.me
    arundev.me about 9 years
    Set client_max_body_size 200M; in /etc/nginx/proxy_params;