Serving static content for your Django project

This procedure will configure your site to serve your Django applications static assets directly from Opalstack's frontend Nginx server via a separate static application. This configuration improves the overall performance of your application in a couple of ways:

  • Since your backend uWSGI server isn't servicing requests for static media, it's able to service dynamic requests more efficiently.
  • Nginx serves static content more efficiently than uWSGI, so your static content will load faster for your visitors.

Create a "Nginx Static Only" application and make a note of the application name.

The remainder of these steps will refer to the application as "mystatic".


Edit your site to add a site route serving the mystatic application on the URI path /static.


SSH into your app's server as the app's shell user.


Edit your project's to set the following variables:

STATIC_ROOT = '/home/username/apps/mystatic'
STATIC_URL = '/static/'

Go into your app directory and activate your Python environment:

cd ~/apps/myapp
source env/bin/activate

Go into your project directory and run the collectstatic management command. This copies your app's static files into your static app directory.

python collectstatic

Run the following commands to restart your Django instance: