首页 > 解决方案 > 通过 gunicorn 运行 django 服务器时模板未加载

问题描述

我正在数字海洋 ubuntu 上部署 django/react 应用程序,为此我创建了一个项目并通过 django 通过创建构建文件夹运行整个应用程序,一切都很好,我创建构建文件夹,使用 python manage.py runserver 0.0 运行 django 服务器。 0.0:8000 并且应用程序加载完美,但是当我使用命令 gunicorn --bind 0.0.0.0:8000 mobilehut.wsgi 通过 gunicorn 运行服务器时,服务器运行成功但模板未加载意味着反应前端未加载,我得到了空白页。

我创建了一个新用户,然后部署,我没有使用 root。我第一次找不到gunicorn有什么问题。有人可以建议我检查什么,是否有 wsgi.py 问题或其他类似的 nginx 文件。

wsgi.py:

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mobilehut.settings')

application = get_wsgi_application()

我们需要检查这个吗?/etc/nginx/sites-enabled/default,在这个我尝试用新用户访问-> root var/www/html,它显示权限被拒绝,这是一个问题

server {
        listen 80 default_server;
        listen [::]:80 default_server;
        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }
}

请提出一些解决方案,我的应用程序在这个 python manage.py runserver 0.0.0.0:8000 上运行良好,但在 gunicorn --bind 0.0.0.0:8000 服务器加载但空白页上没有。

标签: reactjsnginxdjango-rest-frameworkgunicorndigital-ocean

解决方案


推荐阅读