在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的configuration:

 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中的内部服务器错误debugging:

 [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 ''. 

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

考虑到你可以正常运行你的应用程序,但是当你尝试点击pipe理界面时,它失败了,错误500是由未捕获的exception引起的。 如果在settings.py设置了DEBUG = TrueTEMPLATE_DEBUG = True ,则应该从exception中获得更好的信息(例如堆栈跟踪)。

尝试这个:

 sys.path.append(project) 

我有一个类似的问题,我已经解决了这个问题。