django-admin panel missing static files on digitalocean server using nginx


My admin panel works fine and shows up properly but when I put it live on digitalocean server the admin-panel doesn’t show properly and miss styling and static files are not served by nginx for admin-panel.

Here is my nginx config file

File: /etc/nginx/sites-available/django

upstream app_server {
    server unix:/home/django/gunicorn.socket fail_timeout=0;

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /usr/share/nginx/html;

    index index.html index.htm;

    client_max_body_size 4G;
    server_name _;
    keepalive_timeout 5;

    # Your Django project's media files - amend as required
    location /media  {
        alias /home/django/django_project/django_project/media;

    # your Django project's static files - amend as required

    location /static {
        alias /home/django/django_project/django_project/static;

    # Proxy the static assests for the Django Admin panel

    location /static/admin {
        alias /usr/lib/python2.7/dist-packages/django/contrib/admin/static/admin/;

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_redirect off;
        proxy_buffering off;
        proxy_pass http://app_server;

STATIC_ROOT = '/home/django/django_project/django_project/static'
STATIC_URL = '/static/'

MEDIA_ROOT = '/home/django/django_project/django_project/media'
MEDIA_URL = '/media/'

asked 2 years, 3 months ago
Reputation: 1

2 Answers


As your static root and url settings

STATIC_ROOT = '/home/django/django_project/django_project/static'
STATIC_URL = '/static/'

when you do

$ python collectstatic

all static files get collected under the directory /home/django/django_project/django_project/static and your static files appear as /home/django/django_project/django_project/static/admin —> css js images

and it is needed to be served from /home/django/ django_project/ django_project/static/admin only.

But in your nginx config file

location /static/admin {
    alias /usr/lib/python2.7/dist-packages/django/contrib/admin/static/admin;

it is being served from usr/lib/python2.7/dist-packages/django/contrib/admin/static/admin/
so, styles and js are missing.

Remove or comment these lines in /etc/nginx/sites-available/django

#location /static/admin {
#   alias /usr/lib/python2.7/dist-packages/django/contrib/admin/static/admin;

It will work fine then.

answered 2 years, 3 months ago
Reputation: 1

Muchas gracias! me sirvio mucho tu codigo

answered 5 months, 3 weeks ago
Reputation: 1

Your Answer

Nothing to preview

Post Answer

Asked:  2 years, 3 months ago
Viewed:  2295 times
Active:  5 months, 3 weeks ago