我使用Django 1.10 + uWsgi + nginx。 在PROD模式下,靜態文件顯示不出來,這是我的Nginx的錯誤日誌告訴我:Django - 找不到靜態/ CACHE文件
404 ... static/CACHE/js/e3a6fa7588d1.js" failed (2: No such file or directory),
文件夾static/CACHE
保持爲空(所以404的有意義),但爲什麼呢? 我已經爲static/CACHE
設置了775
的權限。
的nginx的conf:
# /etc/nginx/sites/available/mysite_nginx.conf
# the upstream component nginx needs to connect to
upstream bdjango {
server unix:///tmp/mysite.sock; # for a file socket
}
# configuration of the server
server {
# the port your site will be served on
listen 80;
# the domain name it will serve for
server_name dev.mysite.com; # substitute your machine's IP address or FQDN
charset utf-8;
# max upload size
client_max_body_size 8M; # adjust to taste
# Django media
location /media {
alias /var/www/mysite/src/media; # your Django project's media files - amend as required
}
location /static {
alias /var/www/mysite/src/static; # your Django project's static files - amend as required
}
# Finally, send all non-media requests to the Django server.
location/{
uwsgi_pass adjango;
include /var/www/mysite/src/uwsgi_params; # the uwsgi_params file you installed
}
}
Django的設置包含
PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__) + "../../../")
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static')
那麼,爲什麼我的JS/CSS文件不static/CACHE
?
編輯: 解決它:uwsgi_pass是在錯誤的上游位置(這正好是一個不同的網站)指出: uwsgi_pass adjango;
我已經有了。這些文件被複制到'/ static'中,但是它正在'static/CACHE'中查找(縮小的)文件,它是空的。 – FeedTheWeb
那是'django-compressor'嗎? – user73657
是的。但似乎並沒有創建這些文件。 – FeedTheWeb