A
A
Antonov Dmitry2016-01-20 18:39:19
Django
Antonov Dmitry, 2016-01-20 18:39:19

Django 1.9 static on production server?

Hello!
I deployed my Django blog on the server using the nginx + gunicorn bundle.
The page at the specified address is displayed, but there is trouble with static, then the nginx config:

server {
    listen 80;
    server_name darkpy.com;
    access_log  /var/log/nginx/example.log;

     Вариант 1
    #location /static/ {
    #   root /root/blog/myblog/blog/;
    #  expires 30d;
    # }

     Вариант 2, текущий
     location ~* ^.+\.(jpg|jpeg|gif|png|ico|txt|css|js)$ {
                root /root/blog/myblog/_media;
      }

    location / {
        proxy_pass http://127.0.0.1:8000;
        proxy_set_header Host $server_name;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
  }

A little about what I did:
1. I registered a direct path to the statics in the project, tried to change the paths, remove and put "/" (I read that there is a difference) - it did not help.
2. Using the collectstatic command, I collected all the statics, as you can see in Option 2, registered the path - it did not help.
I also looked at the logs:
80.76.103.3 - - [19/Jan/2016:22:08:16 +0300] "GET /static/blog/css/bootstrap.css HTTP/1.1" 403 208 "http://62.109.3.37/" "Mozilla/5.0 (X11; Linux x86_$
80.76.103.3 - - [19/Jan/2016:22:08:16 +0300] "GET /static/blog/style.css HTTP/1.1" 403 208 "http://62.109.3.37/" "Mozilla/5.0 (X11; Linux x86_64) Appl$

Perhaps I misunderstood, but logically, it correctly specifies the path when accessing statics.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir, 2016-01-20
@BlackTrub

403 error is an access error. rights are missing

V
Vladislav Sklyar, 2016-01-20
@VladSkliar

Try to write the path to the static like this:

location /static/ {
        alias   /home/.../django_project/static/;
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question