My setup was a very basic one – a VirtualBox running:
- Ubuntu 12.04
Nginx has a sendfile directive, which defaults to on. It allows nginx to use the Linux kernel’s sendfile() operation to read the requested file from disk. This is typically quicker than using read() and write(). So far, so good.
The problem is that sendfile doesn’t work so well in virtual environments, as noted in nginx’s “Pitfalls” section. The fix turned out to be insanely simple – just turn sendfile off. As it’s a development machine, the performance hit incurred by turning off this feature is pretty negligible. (It would want to be a pretty significant performance hit to outweigh the file truncation!)
In the nginx config http server block, I added:
Once nginx was restarted, I was getting served full static files, and all was well with the world again!