【发布时间】:2015-08-22 09:06:43
【问题描述】:
我已经尝试了大约一整天的时间在生产环境中部署 Django 的静态文件,但直到现在我都没有运气,所以我绝对需要社区的帮助!
我的 nginx 配置是:
worker_processes 1;
user nobody nogroup;
pid /tmp/nginx.pid;
error_log /tmp/nginx.error.log;
events {
worker_connections 1024;
accept_mutex off;
}
http {
include mime.types;
default_type application/octet-stream;
access_log /tmp/nginx.access.log combined;
sendfile on;
upstream app_server {
server unix:/tmp/gunicorn.sock fail_timeout=0;
# For a TCP configuration:
# server 192.168.0.7:8000 fail_timeout=0;
}
server {
listen 80 default;
client_max_body_size 4G;
server_name _;
keepalive_timeout 5;
# path for static files
root /home/ubuntu/src/static;
location / {
# checks for static file, if not found proxy to app
try_files $uri @proxy_to_app;
}
location @proxy_to_app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app_server;
}
error_page 500 502 503 504 /500.html;
location = /500.html {
root /home/ubuntu/src/static;
}
}
}
在我的 django settings.py 文件中,我设置了以下内容:
STATIC_URL = '/static/'
STATICFILES_DIRS = ()
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
当然,我已经运行了collectstatic django 命令,并且路径/home/ubuntu/src/static 中的文件夹包含所有适当的文件。
我的部署仍然没有提供任何静态文件:/
有人知道我的设置有什么问题吗?
提前谢谢你
【问题讨论】:
标签: python django nginx django-staticfiles static-files