在 CentOS 中部署 Django-内部服务器错误 500

在 CentOS 中部署 Django-内部服务器错误 500

我的系统:

CentOS: 5.5 x86_64 GNU/Linux
Apache/2.2.16
mod_wsgi-3.2-1.el5.x86_64
python 2.6.6
django 1.2.3

我的文件example.wsgi:

#!/usr/local/bin/python
import os, site, sys

# add the virtual environment path
site.addsitedir('/home/admin/domains/example.com/env/lib/python2.6/site-packages')
site.addsitedir('/home/admin/domains/example.com/myproject')
site.addsitedir('/home/admin/domains/example.com')

# fix markdown.py (and potentially others) using stdout
sys.stdout = sys.stderr

#Calculate the path based on the location of the WSGI script.
project = os.path.dirname(__file__)
workspace = os.path.dirname(project)
sys.path.append(workspace)

os.environ['PYTHON_EGG_CACHE'] = '/home/admin/domains/example.com/.python-eggs'
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
from django.core.handlers.wsgi import WSGIHandler
application = WSGIHandler()

Apache 配置:

ServerRoot /etc/httpd

<VirtualHost 69.*.*.*:80 >
LoadModule wsgi_module /usr/lib64/httpd/modules/mod_wsgi.so

WSGIScriptAlias / /home/admin/domains/example.com/example.wsgi
WSGIDaemonProcess example user=admin processes=2 threads=25 display-name=%{GROUP}
WSGIProcessGroup example
WSGIApplicationGroup %{GLOBAL}

LogLevel debug

   <Directory /home/admin/domains/example.com>
      Order allow,deny
      Allow from all
   </Directory>

   Alias /robots.txt /home/admin/domains/example.com/public_html/robots.txt
   Alias /static /home/admin/domains/example.com/public_html/static


ErrorDocument 401 "Authentication Error"
ErrorDocument 403 "Forbidden"

 ServerName www.example.com
 ServerAlias www.example.com example.com 
 ServerAdmin [email protected]
 DocumentRoot /home/admin/domains/example.com/public_html
 ScriptAlias /cgi-bin/ /home/admin/domains/example.com/public_html/cgi-bin/

 UseCanonicalName OFF

 SuexecUserGroup admin admin
 CustomLog /var/log/httpd/domains/example.com.bytes bytes
 CustomLog /var/log/httpd/domains/example.com.log combined
 ErrorLog /var/log/httpd/domains/example.com.error.log

</VirtualHost>

我可以执行“syncdb”并导入 PYTHONPATH 中的任何内容。当我运行 example.com 时,一切正常。但是当我运行 example.com/admin 时,它会出现问题:内部服务器错误 在 /var/log/httpd/domains/example.com.error.log 中调试:

[Sun Oct 03 00:01:08 2010] [error] [client 58.186.13.1] Premature end of script headers: example.wsgi
[Sun Oct 03 00:01:08 2010] [debug] mod_deflate.c(602): [client 58.186.13.1] Zlib: Compressed 498 to 210 : URL /500.shtml
[Sun Oct 03 00:01:08 2010] [debug] mod_headers.c(743): headers: ap_headers_output_filter()
[Sun Oct 03 00:01:08 2010] [debug] mod_headers.c(743): headers: ap_headers_output_filter()
[Sun Oct 03 00:01:09 2010] [info] mod_wsgi (pid=22379): Attach interpreter ''.

请帮我解决这个问题。非常感谢!

答案1

假设您可以正常运行应用程序,但尝试访问管理界面时失败,则 ERROR 500 很可能是由未捕获的异常引起的。如果您设置了DEBUG = TrueTEMPLATE_DEBUG = Truesettings.py您应该可以从异常中获得更好的信息(例如堆栈跟踪)。

答案2

尝试这个:

sys.path.append(project)

我遇到过类似的问题,并且已经用这种方法解决了。

相关内容