Skip to main content
 首页 » 编程设计

python之将 cookiecutter-django 和 gunicorn 部署到 digital ocean 的 Production.py 问题

2025年01月19日38jirigala

我使用最新版本的 cookiecutter-django 构建了一个 Django 项目,这似乎在我的本地计算机上以及当我使用各种设置文件通过 python manage.py runserver 运行它时都运行良好。我正在尝试在 Digital Ocean(运行 Ubuntu 16.04)上测试我的 Gunicorn 服务器,但由于某种原因,当正在使用 production.py 时无法让服务器正常运行。

当我在 bash 上执行以下命令时:

gunicorn --bind 0.0.0.0:8000 --env DJANGO_SETTINGS_MODULE=config.settings.test --preload config.wsgi 

一切正常,我得到了这些:

[2018-02-18 23:31:14 -0500] [31662] [INFO] Starting gunicorn 19.7.1 
[2018-02-18 23:31:14 -0500] [31662] [INFO] Listening at: http://0.0.0.0:8000 (31662) 
[2018-02-18 23:31:14 -0500] [31662] [INFO] Using worker: sync 
[2018-02-18 23:31:14 -0500] [31666] [INFO] Booting worker with pid: 31666 

但是当我没有指定设置文件并默认为 production.py 和 gunicorn --bind 0.0.0.0:8000 --preload config.wsgi 时,其中环境变量 DJANGO_SETTINGS_MODULE 设置为 config.settings.production,我只得到这些:

DEBUG 2018-02-18 23:31:55,786 base 31681 140442914699008 Configuring Raven for host: <raven.conf.remote.RemoteConfig object at 0x7fbb5cc0b668> 
INFO 2018-02-18 23:31:55,786 base 31681 140442914699008 Raven is not configured (logging is disabled). Please see the documentation for more information. 

它几乎就卡在那里了。可能导致此问题的原因是什么?

请您参考如下方法:

看起来这是一个 SSL 问题。默认情况下,cookiecutter-django 强制使用 HTTPS,但我的服务器还没有任何证书,因此它失败了。我将以下部分添加到 ~/.bashrc 文件中,它起作用了:

## for testing  
export DJANGO_DEBUG=False (can be True when testing) 
export DJANGO_SECURE_SSL_REDIRECT=True (can be False when testing)