这里是Django初学者
在最终部署到数字海洋液滴时加载静态文件时遇到问题
我用的是Nginx和Gunicorn
我遵循了Traversy Media的教程,但我无法通过我的Digital Ocean ipv4在浏览器中显示静态文件。检查后,它会抛出这些多个错误
Refused to apply style from 'http://162.243.162.127/btre/static/css/all.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
GET 162.243.162.127/:510 GET http://162.243.162.127/btre/static/js/bootstrap.bundle.min.js net::ERR_ABORTED 404 (Not Found)
这是我的nginx设置
server {
listen 80;
server_name 162.243.162.127;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/djangoadmin/pyapps/realestate_project;
}
location /media/ {
root /home/djangoadmin/pyapps/realestate_project;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
}
这是我的gunicorn设置
[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target
[Service]
User=djangoadmin
Group=www-data
WorkingDirectory=/home/djangoadmin/pyapps/realestate_project
ExecStart=/home/djangoadmin/pyapps/venv/bin/gunicorn \
--access-logfile - \
--workers 3 \
--bind unix:/run/gunicorn.sock \
btre.wsgi:application
[Install]
WantedBy=multi-user.target
我曾多次尝试在终端中运行collectstatic,但它不起任何作用。。表示它有“0要收集”
我在本地主机中重新创建了这个问题,结果发现我需要在Nginx中的“/static/”URL位置之前添加project folders应用程序的名称,就像在project folders应用程序的“settings.py”中一样
sudo nano/etc/nginx/可用站点/btre\u项目
更改:
/静态/
致:
/my_应用程序/静态
相关问题 更多 >
编程相关推荐