Nginx无法为静态和媒体图像提供服务

时间:2015-03-07 05:53:48

标签: django nginx gunicorn digital-ocean

我在使用gunicorn和nginx运行的DigitalOcean Droplet上有一个django应用程序。该网站正在运行,但静态文件正在提供404.以下是我的' / etc / nginx / sites-available / django-project'文件:

server {

        #listen 80 default_server;
        #listen [::]:80 default_server ipv6only=on;

        server_name aakar.in;

        root /usr/share/nginx/html;
        index index.html index.htm;

        #access_log off;

        client_max_body_size 4G;
        #server_name _;

        keepalive_timeout 5;

        location /media  {
           alias /home/django/django_project/django_project/media;
        }

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

        location / {

                proxy_pass http://127.0.0.1:9000;
                proxy_redirect off;
                proxy_set_header X-Forwarded-Host $server_name;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header Host $http_host;
                add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM N$
        }
    }

1 个答案:

答案 0 :(得分:0)

更正:

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

立即工作。