Search code examples
nginxvagrantvirtualboxgunicornsendfile

Nginx and Gunicorn with Virtualbox serves old verison of Django static files padded/cropped to new file size, sendfile off doesn't work


My problem is the same one as described here and here, but with the exception that setting sendfile off; in nginx.conf does not help.

I'm running Vagrant with Virtualbox (Ubuntu 16.04) and Nginx, Gunicorn, and Django. I use this setup for development, so I want to avoid having to call collectstatic every time a file is changed. As such, Nginx routes all requests to Gunicorn (even '/static/'), and Gunicorn serves the static files using this approach:

if settings.DEBUG:
    from django.contrib.staticfiles.urls import staticfiles_urlpatterns
    urlpatterns += staticfiles_urlpatterns()

This works, with the exception that if I change something in a static file, the contents are not updated, only the file size. I have tried setting sendfile off; in nginx.conf, and also in my Gunicorn configuration. Still, the problem remains. Is there any way I could try to narrow down the possible cause of this issue?

All Django files are in folder that is shared with the Windows 10 host system, but if I use vagrant ssh and check out the files, they have updated properly.

Edit: The problem persists if I run Gunicorn only without Nginx, so it seems to be a Gunicorn/Django problem.


Solution

  • Figured it out.

    I needed to run Gunicorn with the --no-sendfile flag as well. I tried setting it in my ini-file before (no_sendfile = True), which did not work. However, adding --no-sendfile to my Gunicorn run command in supervisor worked!