Jordan Teichmann

Deploying a Django app on Caprover

Free and open source Paas + free and open source Django

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.

Serving static and media files

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.

Serving files locally

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:

  1. Ensure your CapRover app has persistent storage. Create a Persistent Directory that connects a path inside your app to a path at /captain/data/nginx-shared/{your}/{folder}. Create the directories and permissions on both sides. The goal is for your app to place media files in a location that CapRover will then expose to the rest of the system.
  2. Now that your media files are also available at /captain/data/nginx-shared, you can modify your nginx file in your app to serve these files. CapRover makes these files available at /nginx-shared, so:
location /media/ {
    alias /nginx-shared/your/folder/;

502 error and no app log output

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.