简体   繁体   English

使用gunicorn运行Django:错误请求(400)

[英]Running Django with gunicorn: Bad Request (400)

I am following this tutorial to set up a Django application and serve it with Gunicorn on a Debian DigitalOcean server: http://michal.karzynski.pl/blog/2013/06/09/django-nginx-gunicorn-virtualenv-supervisor/ 我正在按照本教程设置Django应用程序并将其与Gunicorn一起在Debian DigitalOcean服务器上使用: http : //michal.karzynski.pl/blog/2013/06/09/django-nginx-gunicorn-virtualenv-supervisor/

I have got as far as the section starting "Now that you have gunicorn, you can test whether it can serve your Django application by running the following command". 我已经从“现在您已经有了gunicorn,您可以通过运行以下命令来测试它是否可以为Django应用程序服务”这一节开始了。 Now I'm stuck. 现在我被卡住了。

In other words, I can successfully run the application using python manage.py runserver , but not by using gunicorn. 换句话说,我可以使用python manage.py runserver成功运行该应用程序,但不能使用gunicorn。

I've successfully accessed my app with: 我已经通过以下方式成功访问了我的应用:

$ python manage.py runserver xx.xx.xx.xx:8000 

Now from the same directory, I'm trying to run: 现在,从同一目录中,我正在尝试运行:

$ gunicorn my_django.wsgi:application --bind xx.xx.xx.xx:8001

It appears to start OK, but when I go to http://xx.xx.xx.xx:8001 , I see: 它似乎开始正常运行,但是当我转到http://xx.xx.xx.xx:8001时 ,我看到了:

Bad Request (400)

I'm not sure how to debug this: there's nothing in /var/log/gunicorn/ . 我不确定如何调试它: /var/log/gunicorn/没有任何内容。

I have set ALLOWED_HOSTS=['xx.xx.xx.xx'] in my settings file. 我在设置文件中设置了ALLOWED_HOSTS=['xx.xx.xx.xx']

UPDATE: Being an idiot: gunicorn was looking in production settings file, not local settings file. 更新:是个白痴:gunicorn在生产设置文件中查找,而不是本地设置文件中查找。 Setting the ALLOWED_HOSTS in production settings fixed it. 在生产设置中设置ALLOWED_HOSTS可以修复该问题。

I'd still really like to know how to debug problems like this though. 我仍然非常想知道如何调试这样的问题。

The answer: gunicorn was looking in production settings file, not local settings file. 答案:gunicorn正在生产设置文件中查找,而不是本地设置文件中查找。 Setting the ALLOWED_HOSTS in production settings fixed it. 在生产设置中设置ALLOWED_HOSTS可以修复该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM