Oct. 9, 2021
CapRover is a self-hosted "platform as a service", a bit like Netlify or Heroku, but you can run it yourself. I ran into a few challenges during my first Django app deployment on CapRover, and this is where I'm taking notes on what I learned.
CapRover makes it easy to serve your application, but serving your Django app won't provide you with access to your static or media files, since Django doesn't serve these in production.
There are a number of ways you can solve this. For one, you might be serving your static and media assets through a storage service like S3. If you're just running something small like me, you may be happy with keeping files on disk and serving them locally. Below is how I set this up.
For static files, I recommend using Whitenoise. This is quick to do, highly performant, and will serve static files without changes to your app.
For media files, we can do a bit more setup to serve them directly from nginx:
location /media/ {
alias /nginx-shared/your/folder/;
}
If you're seeing a 502 error and it doesn't seem like your app is running at all, it may be an issue with your configuration. Setting "Path on Host" for persistent storage to a path that doesn't exist is one way this can happen.
Looking for a solid VPS provider? I have been using Linode for years for personal and professional projects (link includes referral code).
Have a reply to this post? Reply via email.