Nginx基于文件大小的油门下载速度

我使用mp4模块从源代码编译的nginx/1.11.11 ,我正在提供从300MB大小到8GB的video文件。

我正在考虑实施类似于谷歌驱动器的油门系统。 如果文件的大小设置的很大, limit_rate ,如果文件的大小很小,则设置一个较小的limit_rate 。 问题是我找不到获取服务文件大小的方法。

我的default.conf文件如下所示:

 server { listen 80; server_name _; # change this for your server root /var/www; index index.php; client_max_body_size 5G; proxy_read_timeout 60000000; # handle requests to the API location ~ /api/v2/(.+)$ { if (!-e $request_filename) { rewrite ^/api/v2/(.*) /api/v2/index.php?_page_url=$1 last; } fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param MOD_X_ACCEL_REDIRECT_ENABLED on; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 location ~ \.php$ { if (!-e $request_filename) { rewrite ^/(.*) /index.php?_page_url=$1 last; } fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_read_timeout 180000000; fastcgi_param MOD_X_ACCEL_REDIRECT_ENABLED on; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location / { if (!-e $request_filename) { rewrite ^/(.*) /index.php?_page_url=$1 last; } } location /files/ { root /var/www; aio threads; internal; mp4; limit_rate_after 5m; limit_rate 400k; } # these locations would be hidden by .htaccess normally location /core/logs/ { deny all; }