2013-02-26 108 views
10

我在CentOS上部署了一個Django應用程序。這裏是我的httpd.conf文件看起來是這樣的:Django Apache mod_wsgi 500

WSGISocketPrefix /var/run/wsgi 
<VirtualHost *:80> 

    WSGIDaemonProcess safe python-path=/usr/lib/python2.6/site-packages 
    WSGIProcessGroup safe 
    WSGIScriptAlias//opt/safe/safe/wsgi.py 

    <Directory /opt/safe/safe/> 
     Order deny,allow 
     Allow from all 
    </Directory> 
</VirtualHost> 

編輯:這是我TEMPLATE_DIRS

TEMPLATE_DIRS = (
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". 
    # Always use forward slashes, even on Windows. 
    # Don't forget to use absolute paths, not relative paths. 
    "/opt/safe/static/templates", 
    "/var/www/html/static/templates", 
) 

編輯:這是我的聯繫/電子郵件設置:

ADMINS = (
# ('Your Name', '[email protected]'), 
('David', '[email protected]'), 
) 

SEND_BROKEN_LINK_EMAILS = True 

DEFAULT_FROM_EMAIL = '[email protected]' 
SERVER_EMAIL = DEFAULT_FROM_EMAIL 

在我模板目錄下,我定義了一個自定義的500.html文件。當我將我的settings.py設置爲DEBUG = False時,如果沒有看到此自定義500.html頁面,我無法在我的網站上找到任何地方。

更奇怪的是事實是日誌文件中沒有錯誤 - 所以我不確定在哪裏看或如何進行。我知道它可以看到模板,因爲我的自定義500.html文件,但我不知道是什麼導致500內部服務器錯誤。

編輯:進一步的配置後,我設法得到了一些錯誤輸出(感謝@馬特·史蒂文斯),這裏是日誌輸出:

Traceback (most recent call last): 
File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py", line 89, in get_response 
response = middleware_method(request) 
File "/usr/lib/python2.6/site-packages/django/middleware/common.py", line 55, in process_request 
host = request.get_host() 
File "/usr/lib/python2.6/site-packages/django/http/__init__.py", line 223, in get_host 
"Invalid HTTP_HOST header (you may need to set ALLOWED_HOSTS): %s" % host) 
SuspiciousOperation: Invalid HTTP_HOST header (you may need to set ALLOWED_HOSTS): [my ip address] 
+0

當您將debug設置爲true時,一切功能是否正常? – 2013-02-26 19:16:05

+0

是的 - 我可以正常訪問所有內容(我的所有URL都可以工作,一切都可以)。 – lightningmanic 2013-02-26 19:20:50

+0

你的template_dirs元組是什麼樣的? – 2013-02-26 21:32:12

回答

12

原來我需要我的IP地址在我的settings.py文件添加到「ALLOWED_HOSTS」。由於記錄錯誤,我終於看到了。

實際代碼:

ALLOWED_HOSTS = ['my.server.ip.address'] 

一個Apache重新啓動後,一切現在能正常使用!

+2

感謝您回來發佈解決方案!從來不知道'ALLOWED_HOSTS',看起來像一個新的安全功能:http://git.io/9Ytk6A – Matt 2013-02-27 18:26:39

+0

嗯,這不是你應該添加的IP地址,而是一個有效的HTTP主機。通過使用IP地址訪問服務器時,這是相同的,但您可能希望在生產環境中將其設置爲FQDN。請參閱[Django文檔](https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts)。 – gertvdijk 2013-05-02 08:33:00

8

你可以嘗試登錄的一切文件到naildown原因。

# in your settings file 
LOGGING = { 
    'version': 1, 
    'disable_existing_loggers': False, 
    'filters': { 
     'require_debug_false': { 
      '()': 'django.utils.log.RequireDebugFalse' 
     } 
    }, 
    'handlers': { 
     'mail_admins': { 
      'level': 'ERROR', 
      'filters': ['require_debug_false'], 
      'class': 'django.utils.log.AdminEmailHandler' 
     }, 
     'logfile': { 
      'class': 'logging.handlers.WatchedFileHandler', 
      'filename': '/var/log/django/error.log' 
     }, 
    }, 
    'loggers': { 
     'django.request': { 
      'handlers': ['mail_admins'], 
      'level': 'ERROR', 
      'propagate': True, 
     }, 
     'django': { 
      'handlers': ['logfile'], 
      'level': 'ERROR', 
      'propagate': False, 
     }, 
    } 
} 
+0

這並沒有把任何東西放在「/ var/log/django」中...... – lightningmanic 2013-02-27 13:38:43

+3

不知道爲什麼它一開始沒有寫任何東西 - 但經過一些其他更改和一些權限修改後,我能夠獲得日誌吐出東西。謝謝! – lightningmanic 2013-02-27 14:14:38