Skip to content Skip to sidebar Skip to footer

Why Won't Newly Installed Django App With Nginx Serve Static Assets?

I have a Mac running OS X 10.9.3. I am trying to setup a Django application backed by a PostgreSQL database served by gunicorn, with static assets served by NGINX. I'm an old hand

Solution 1:

Static files are only served by Django when the debug server is being used. When the site is being handled by a separate web server you need to configure the web server to serve the static files itself.

Solution 2:

Actually, it is recommended to use Django's own development server(python manage.py runserver) while you are on localhost(from my years' experience with Django and virtualenv). Since it save your precious time configuring the nginx locally.

However, if you do want to use Nginx to serve you static files locally, you may want to copy django's contrib **/admin static file directory to where your virtualenv points to**. Your virtualenv file(like a *.nginx file) of nginx will look like this:

 server_name  localhost;

 location /static {
     alias /path/to/where/your/admin/static/directory/is;
     autoindex on;
     access_log off; #optional
  }

Then restart nginx you probably will get it working. PS: for more about installing and configuring Nginx locally on a Mac, you may want to check this out.

Post a Comment for "Why Won't Newly Installed Django App With Nginx Serve Static Assets?"