【发布时间】:2021-07-18 17:45:30
【问题描述】:
在 gunicorn 和 nginx 之前,一切都运行良好,我们将静态文件提供给网站。 但是现在,不要再工作了。 任何帮助是极大的赞赏。 非常感谢。
Settings.py
STATICFILES_DIRS = [
'/root/vcrm/vcrm1/static/'
]
STATIC_ROOT = os.path.join(BASE_DIR, 'vcrm/static')
STATIC_URL = '/static/'
MEDIA_ROOT = '/root/vcrm/vcrm1/vcrm/media/'
MEDIA_URL = '/media/'
/etc/nginx/sites-available/vcrm
server {
listen 80;
server_name 195.110.58.168;
location = /favicon.ico { access_log off; log_not_found off; }
location /static {
root /root/vcrm/vcrm1/vcrm;
}
location = /media {
root /root/vcrm/vcrm1/vcrm;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
}
当我运行 collectstatic 时:
You have requested to collect static files at the destination
location as specified in your settings:
/root/vcrm/vcrm1/vcrm/static
This will overwrite existing files!
Are you sure you want to do this?
然后:
Found another file with the destination path 'admin/js/vendor/jquery/jquery.min.js'. It will be
ignored since only the first encountered file is collected. If this is not what you want, make sure
every static file has a unique path.
0 static files copied to '/root/vcrm/vcrm1/vcrm/static', 251 unmodified.
【问题讨论】:
-
STATIC_ROOT是 collectstatic 收集静态文件的地方,它应该是一个空文件夹。显然,在你的情况下它不是空的。 -
你能澄清你所说的不工作是什么意思吗?具体来说,您得到的是 404、403、502 还是其他?另外,您请求的 URL 是什么?
-
网址是195.110.58.168可以输入查看。我没有收到任何错误,就像我看到该网站但没有任何静态文件,如 css 等。请帮助?我的配置看起来不错?
-
我无法访问该 IP 地址。另外,当您说“没有任何静态文件”时,您所说的没有是什么意思?同样,您遇到了什么错误?我怀疑您混淆了 Nginx 的
root和alias指令,但我无法确定,因为我不知道错误类型。
标签: python django nginx gunicorn django-staticfiles