Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx Serving static large file

I have a bigFile.avi which is 800MB and is at http://example.com/bigFile.avi.

When I use this link to download the bigFile.avi from the browser, my nginx server jumps to 100% CPU load during the download session with no static content nor PHP (normal PHP scripts use 1-3% CPU).

Is this normal for the server? Does it consume so much CPU to serve large files?

I have even tried turning off the gzip in the nginx config, but there is not much difference.

like image 931
samfriend Avatar asked Sep 13 '11 01:09

samfriend


People also ask

Does nginx serve static files?

To serve static files with nginx, you should configure the path of your application's root directory and reference the HTML entry point as the index file. In this example, the root directory for the snake deployment is /home/futurestudio/apps/snake which contains all the files.

How do I limit the size of a nginx download?

By default, NGINX® has a upload limit of 1 MB per file. By editing client_max_body_size, you adjust the file upload size. Use the http, server, or location block to edit client_max_body_size. Changes to the http block affect all server blocks (virtual hosts).

How do you serve a static file?

To serve static files such as images, CSS files, and JavaScript files, use the express.static built-in middleware function in Express. The root argument specifies the root directory from which to serve static assets. For more information on the options argument, see express.static.


2 Answers

As nginx can write large files in disk before sending them to the client, it's often a good idea to disable this cache if the site is going to serve big static files, with something like:

location / {
    proxy_max_temp_file_size 0;
}
like image 91
merlucin Avatar answered Sep 23 '22 04:09

merlucin


Take a look at these articles

  • http://www.facebook.com/topic.php?uid=122166917825068&topic=325
  • https://calomel.org/nginx.html (search for the "sendfile off" section)

I will admit that some of that is beyond me. But in short they suggest disabling sendfile, enabling aio, and increasing your output buffers if you're sending large (>4MB) files. What I took away is that most default server configs assume many small files will be sent, rather than few or many large files. These two different scenarios can require some very different configs to work efficiently.

like image 10
bioneuralnet Avatar answered Sep 21 '22 04:09

bioneuralnet