我使用的是Django 1.10 + uWsgi + nginx。 在Prod模式下,静态文件没有出现,这就是我的nginx错误日志告诉我的事情:
404 ... static/CACHE/js/e3a6fa7588d1.js" failed (2: No such file or directory),
文件夹static/CACHE
仍为空(所以404有意义),但为什么呢?
我已将775
的权限设置为static/CACHE
。
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;
答案 0 :(得分:1)
可能是django-compressor
失败了。
您是否尝试在设置中使用DEBUG = True
和COMPRESS_ENABLED = True
,看看它是否有效?
https://django-compressor.readthedocs.io/en/latest/settings/#django.conf.settings.COMPRESS_ENABLED
或者,我建议您在生产中设置ADMINS
,以便通过电子邮件向您发送任何错误,或在生产设置中设置sentry。
答案 1 :(得分:1)