2

我使用最新版本的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.pywithgunicorn --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.

它几乎只是卡在那里。什么可能导致此问题?

4

1 回答 1

1

看起来这是一个 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)
于 2018-02-19T21:36:21.433 回答