Django 1.6 uWSGI + 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上配置了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
你需要设置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;
}
}