2017-03-29 103 views
0

我使用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;

回答

1

這可能是django-compressor失敗。

您是否嘗試在您的設置中使用DEBUG = TrueCOMPRESS_ENABLED = True並查看它是否有效?

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

另外,我建議有ADMINS設置在生產,因此發電子郵件給你任何錯誤,或在生產安裝安裝sentry

+0

我已經有了。這些文件被複制到'/ static'中,但是它正在'static/CACHE'中查找(縮小的)文件,它是空的。 – FeedTheWeb

+0

那是'django-compressor'嗎? – user73657

+0

是的。但似乎並沒有創建這些文件。 – FeedTheWeb

1
  1. 您使用的是CACHE嗎?
  2. 您是否已正確顯示STATIC_URL和STATIC_ROOT?
  3. DEBUG = False?
  4. 您是否使用任何第三方工具來緩存/管理您的靜態文件?