Django - 找不到静态/缓存文件



我正在使用Django 1.10 + uWsgi + nginx。在生产模式下,静态文件不显示,这是我的nginx错误日志告诉我的:

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;

  1. 您是否正在使用缓存?
  2. 你有没有蔑视STATIC_URL,STATIC_ROOT正确。
  3. 调试 = 假吗?
  4. 您是否使用任何第三方工具来缓存/绘制静态文件?
可能是

django-compressor失败了。

您是否尝试过在设置中设置DEBUG = TrueCOMPRESS_ENABLED = True,看看它是否有效?

https://django-compressor.readthedocs.io/en/latest/settings/#django.conf.settings.COMPRESS_ENABLED

或者,我建议在生产环境中进行ADMINS设置,以便通过电子邮件向您发送任何错误,或在生产设置中设置哨兵。

最新更新