4

I know this question has been discussed. But the problem persists, and I am left without any solution. Please help.

My platform is: Ubuntu 14.04 LTS, Python 3.4, MySQL 5.5, Django 1.7, Nginx 1.4.6, and Gunicorn 19.1.1.

When I set DEBUG = False in the production server, my Django application runs OK for maybe half a day. And after that, the annoying Server Error (500) always appear for certain functions, but not every one. If I turn DEBUG = True, everything will be fine.

I also set ALLOWED_HOSTS = ['*']. Some said that it should not be a wild card in production. But my app is for public, how should I set it? Others said that it should be 'localhost'. But only localhost can access the server? Why go production, then?

Is there a standard solution to this problem? Thanks.

Community
  • 1
  • 1
Randy Tang
  • 4,283
  • 12
  • 54
  • 112
  • 2
    Might not be related to `DUBUG` :) Do you have logging enabled, or configured ADMINS that receive 500 error emails? – alecxe Dec 18 '14 at 03:18
  • Thanks alecxe. Would you advise how to enable logging? I have logged Nginx and Gunicorn. – Randy Tang Dec 18 '14 at 03:29

1 Answers1

5

500 error on production is not something you should make guesses about.

You need to know exactly what, where and when is it happening:

  • enable Django Logging and log, log, log
  • set ADMINS configuration setting and receive emails on critical errors

ADMINS

Default: () (Empty tuple)

A tuple that lists people who get code error notifications. When DEBUG=False and a view raises an exception, Django will email these people with the full exception information.

Other related materials:

I understand that it doesn't provide you with an answer and doesn't directly solve your problem, but I hope you get my point, thanks.

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • OK, I set ADMINS (https://docs.djangoproject.com/en/dev/ref/settings/#admins), gmail smtp (http://www.mangooranges.com/2008/09/15/sending-email-via-gmail-in-django/), and logging (https://docs.djangoproject.com/en/dev/topics/logging/). Everything works OK now. Will keep on watching. Thanks a million, alexce. – Randy Tang Dec 18 '14 at 05:44