django nginx 不提供静态文件
django nginx not serving static files
我正在使用 nginx 和 gunicorn 部署 django。当我访问网站时出现以下错误。
open() "/home/x/aroundu/core/static/static/rest_framework/js/default.js" failed
是访问静态文件错误,因为路径应该是这样的
open() "/home/x/aroundu/core/core/static/rest_framework/js/default.js" failed
server {
listen 80;
location /static/ {
alias /home/x/aroundu/core/core/static/;
}
location /media/ {
alias /home/x/aroundu/core/media/;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
}
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = "/media/"
这应该是:
location /static/ {
root /home/x/aroundu/core/core/;
}
location /media/ {
root /home/x/aroundu/core/;
}
此外,对于静态,您有 /core/core/,而对于媒体,您只有 /core/。我不知道哪个是正确的,但根据您的设置,它们应该是相同的。
我正在使用 nginx 和 gunicorn 部署 django。当我访问网站时出现以下错误。
open() "/home/x/aroundu/core/static/static/rest_framework/js/default.js" failed
是访问静态文件错误,因为路径应该是这样的
open() "/home/x/aroundu/core/core/static/rest_framework/js/default.js" failed
server {
listen 80;
location /static/ {
alias /home/x/aroundu/core/core/static/;
}
location /media/ {
alias /home/x/aroundu/core/media/;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
}
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = "/media/"
这应该是:
location /static/ {
root /home/x/aroundu/core/core/;
}
location /media/ {
root /home/x/aroundu/core/;
}
此外,对于静态,您有 /core/core/,而对于媒体,您只有 /core/。我不知道哪个是正确的,但根据您的设置,它们应该是相同的。