【问题标题】:Gunicorn not loading react frontend in django react nginx configuration digitaloceanGunicorn 未在 django 中加载反应前端反应 nginx 配置 digitalocean
【发布时间】:2020-04-08 16:10:24
【问题描述】:
我正在尝试使用 nginx gunicorn 在 digitalocean 上部署 django react 应用程序。我已经创建了 virtualenv,当我尝试运行时:
gunicorn --bind 0.0.0.0:8000 myproject.wsgi
它不加载反应前端,而是加载 django 后端。我知道 gunicorn 不是静态的,但它会加载错误的白页:
You need to enable JavaScript to run this app.
【问题讨论】:
标签:
django
python-3.x
django-rest-framework
gunicorn
digital-ocean
【解决方案1】:
因为 react 需要将 js 库文件发送到服务器,并且由于它可能会给出错误而未呈现。通过nginx服务器所有的静态文件
server {
listen 80;
server_name example.com;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/django/sample;
}
location / {
include uwsgi_params;
uwsgi_pass unix:/home/django/sample/sample.sock;
}
}