Z
Z
zzmaster2019-07-23 13:12:19
Nginx
zzmaster, 2019-07-23 13:12:19

Why does nginx mess up the Content-length header?

I'm going to send a video file with a PHP script, but the Content-length header that reaches the client is different from the value that the script gave out. (Tried also Content-type which is commented out - didn't help)

header("HTTP/1.1 200 OK");
 	//header("Content-Type: video/webm"); 
  header("Content-Type: application/octet-stream"); 
  header("Content-length: " . filesize($file)); 
  header('Content-Disposition: attachment; filename="' . $output_name . '"'); 
  print("Real Content-length: " . filesize($file));

And this is how curl traces it
0067: Accept: */*
0074: 
<= Recv header, 17 bytes (0x11)
0000: HTTP/1.1 200 OK
<= Recv header, 15 bytes (0xf)
0000: Server: nginx
<= Recv header, 37 bytes (0x25)
0000: Date: Mon, 22 Jul 2019 07:30:01 GMT
<= Recv header, 40 bytes (0x28)
0000: Content-Type: application/octet-stream
<= Recv header, 20 bytes (0x14)
0000: Content-Length: 24
<= Recv header, 24 bytes (0x18)
0000: Connection: keep-alive
<= Recv header, 24 bytes (0x18)
0000: Keep-Alive: timeout=60
<= Recv header, 26 bytes (0x1a)
0000: X-Powered-By: PHP/5.4.16
<= Recv header, 57 bytes (0x39)
0000: Content-Disposition: attachment; filename="lalafa.webm"
<= Recv header, 2 bytes (0x2)
0000: 
<= Recv data, 24 bytes (0x18)
0000: Real Content-length: 49584338

PHP version is old, 5.4, but probably the problem is in nginx.
nginx version: nginx/1.12.2
Installed Vesta.
server {
    listen       11.22.33.44:80 default;
    server_name  _;
    #access_log  /var/log/nginx/11.22.33.44.log main;
    location / {
        proxy_pass  http://11.22.33.44:8080;
   }
}
server {
    listen       127.0.0.1:8084 default;
    server_name  _;
    server_name_in_redirect  off;
    location / {
        stub_status on;
        access_log   off;
   }
}
server {
    listen      11.22.33.44:80;
    server_name getfile.qu www.getfile.qu;
    error_log  /var/log/httpd/domains/getfile.qu.error.log error;

    location / {
        proxy_pass      http://11.22.33.44:8080;
        location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|tif|tiff|css|js|htm|html|ttf|otf|webp|woff|txt|csv|rtf|doc|docx|xls|xlsx|ppt|pptx|odf|odp|ods|odt|pdf|psd|ai|eot|eps|ps|zip|tar|tgz|gz|rar|bz2|7z|aac|m4a|mp3|mp4|ogg|wav|wma|3gp|avi|flv|m4v|mkv|mov|mpeg|mpg|wmv|exe|iso|dmg|swf)$ {
            root           /home/admin/web/getfile.qu/public_html;
            access_log     /var/log/httpd/domains/getfile.qu.log combined;
            access_log     /var/log/httpd/domains/getfile.qu.bytes bytes;
            expires        max;
            try_files      $uri @fallback;
        }
    }

    location /error/ {
        alias   /home/admin/web/getfile.qu/document_errors/;
    }

    location @fallback {
        proxy_pass      http://11.22.33.44:8080;
    }

    location ~ /\.ht    {return 404;}
    location ~ /\.svn/  {return 404;}
    location ~ /\.git/  {return 404;}
    location ~ /\.hg/   {return 404;}
    location ~ /\.bzr/  {return 404;}

    include /home/admin/conf/web/nginx.getfile.qu.conf*;
}

What is actually happening and how to fix it? Thank you.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question