4

I've searched some time, but couldn't find any tutorial on how to serve static and user uploaded (/media/) files in conjunction with Daphne. I've read that Apache doesn't support ASGI, that it may be possible to use Nginx, but nothing specific.

I've also tried whitenoise (which only supports static files) and dj-static (which only supports WSGI). I'd like not to use external CDNs, for privacy reasons.

Can you provide any hints on possible setups?

2080
  • 1,223
  • 1
  • 14
  • 37

1 Answers1

4

In production it is better to let nginx/apache to serve static/media files. If you are using nginx, add this to your config.

location /static {
    alias {{ project_root }}/static;
}

location /media {
    alias {{ project_root }}/media;
}

Neither apache nor nginx support ASGI. You have to use daphne or uvicorn which will run behind nginx/apache to support ASGI. I have also written an article on django channels deployment, if you need more details.

Chillar Anand
  • 27,936
  • 9
  • 119
  • 136
  • Yes, this is what I've ended up using, thank you very much! I wish there was a fork of rednoise that supported ASGI (because this would enable one to limit specific media file access to logged in users etc.) – 2080 Jun 21 '18 at 03:58