3 ms·
Related...Apache, nginx, and probably other web servers can be coerced into handling sendfile() for you. https://tn123.org/mod_xsendfile/ https://tn123.org/mod
by tyingq 11y ago
Related...Apache, nginx, and probably other web servers can be coerced into handling sendfile() for you.
https://tn123.org/mod_xsendfile/ https://tn123.org/mod_xsendfile/
https://www.nginx.com/resources/wiki/start/topics/examples/xsendfile/# https://www.nginx.com/resources/wiki/start/topics/examples/x...
- dullgiulio 11y agoAlso any webserver written in Go uses sendfile transparently when sending mmap-able data down to a socket.
- mixmastamyk 11y agoThat nginx config is hard to grok. Is it really that complicated and not just "sendfile = on" ?
- tyre 11y agoYou are correct! There is a simple sendfile in the http core module. http://nginx.org/en/docs/http/ngx_http_core_module.html#sendfile http://nginx.org/en/docs/http/ngx_http_core_module.html#send...
- dividuum 11y agoIf you have a public url for a file, then you can just point your users to that url and use sendfile=on. Nginx will then use sendfile. But consider the usecase where you have a bigger download hidden behind some kind of authentication. You'd do that authentication in your normal backend and return the X-Accel-Redirect header in your response. Nginx will then take over and send the data using sendfile.
- tyingq 11y agoI linked to the "harder to grok" piece because that's what would give you programmatic control by setting an X header. That's as opposed to calling sendfile() yourself from your app. Helpful if you're trying to do something more than just serve up static files...like maybe in a page cache, where you also want dynamic control over other headers, etc. The simpler sendfile=on would just be instructing nginx to use it for static files.