Django 1.6 uWSGI + nginx不会提供静态文件

时间:2014-06-24 01:21:08

标签: python django nginx

我有一个Django 1.6应用程序用于测试目的,如下所示:

media folder -> /home/josealejandro93/Desktop/Soporte/media
static folder -> /home/josealejandro93/Desktop/Soporte/static
root folder -> /home/josealejandro93/Desktop/Soporte  # manage.py lives here!

我设法在Linux Arch上使用this tutorial配置uwsgi,当我运行

uwsgi --http :8000 --module soporte.wsgi

我可以看到我的应用程序在localhost:8000上运行但是按照上面指出的教程中的配置说明,我无法提供静态文件,所以我为/ etc / nginx /尝试了一个新的配置nginx.conf:

worker_processes  1;


events {
    worker_connections  1024;
}


http {
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;

        location / {
            include /etc/nginx/mime.types;      
            root   /home/josealejandro93/Desktop/Soporte;
            index  index.html index.htm;
        }


        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }
    }


}

如您所见,该文件只是一个基本配置文件,但我仍然无法提供静态文件。

关于我做错了什么的任何想法?

1 个答案:

答案 0 :(得分:0)

您应该配置nginx以识别和提供媒体和静态文件:

server {
    listen       80;
    server_name  localhost;

    location / {
        include /etc/nginx/mime.types;      
        root   /home/josealejandro93/Desktop/Soporte;
        index  index.html index.htm;
    }

    location /static/ { 
        alias /home/josealejandro93/Desktop/Soporte/static;
    }

    location /media/ { 
        alias /home/josealejandro93/Desktop/Soporte/media;
    }
}
相关问题