我正在尝试使用 mod_wsgi 使我的 django 项目与httpd一起工作 . 但我一直得到"500 Internal Server Error" . 我正在使用 PostgreSQL Postgis 数据库 . 我的操作系统是Fedora 20 .
真正奇怪的是:
-
当我使用Django开发服务器而不是httpd时,项目工作得很好 .
-
当我使用Postgis以外的其他东西时也可以正常工作,即当我替换文件settings.py中的followig行时:
'ENGINE': 'django.contrib.gis.db.backends.postgis',
由任何其他数据库(mysql,sqlite3 ..),如:
'ENGINE': 'django.db.backends.mysql',
这是我的django项目的httpd配置文件(假设它叫 testproject
)(我把这个文件放在 /etc/httpd/conf.d
中):
<VirtualHost *:80>
ServerName testproject.com
DocumentRoot /var/www/testproject
WSGIProcessGroup testproject
WSGIDaemonProcess testproject threads=4
WSGIScriptAlias / /var/www/testproject/django.wsgi
Alias /static/ "/var/www/testproject/static/"
<Location "/media">
SetHandler None
</Location>
<LocationMatch "\.(jpg|gif|png|js|css)$">
SetHandler None
</LocationMatch>
<Directory /var/www/testproject>
WSGIProcessGroup testproject
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
显然产生错误的项目设置部分( settings.py
):
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'db_name',
'USER': 'db_user',
'PASSWORD': '',
'HOST': '',
'PORT': '',
}
}
当我尝试访问URL testproject.com
时,我得到"500 Internal Server Error",httpd错误日志如下:
[Mon May 12 14:34:35.462830 2014] [:info] [pid 20762] [remote 127.0.0.1:33403] mod_wsgi (pid=20762, process='testproject', application=''): Loading WSGI script '/var/www/testproject/django.wsgi'.
[Mon May 12 14:34:35.799954 2014] [core:error] [pid 20537] [client 127.0.0.1:49565] End of script output before headers: django.wsgi
[Mon May 12 14:34:35.884215 2014] [core:notice] [pid 20530] AH00052: child pid 20762 exit signal Segmentation fault (11)
[Mon May 12 14:34:35.884237 2014] [:info] [pid 20530] mod_wsgi (pid=20762): Process 'testproject' has died, restarting.
[Mon May 12 14:34:35.884240 2014] [:info] [pid 20530] mod_wsgi (pid=20762): Process 'testproject' terminated by signal 11
[Mon May 12 14:34:35.884728 2014] [:info] [pid 20978] mod_wsgi (pid=20978): Starting process 'testproject' with uid=48, gid=48 and threads=4.
[Mon May 12 14:34:35.884981 2014] [:info] [pid 20978] mod_wsgi (pid=20978): Initializing Python.
[Mon May 12 14:34:35.892051 2014] [:info] [pid 20978] mod_wsgi (pid=20978): Attach interpreter ''
我坚持认为这个错误只发生在使用 django.contrib.gis.db.backends.postgis
,但是使用 django.db.backends.*
中的任何一个都可以正常工作 .
任何帮助或想法将不胜感激 .
1 回答
我刚刚发现了问题所在 . 它来自 SELinux policy ,显然是否认httpd访问该页面的权限 .
我在
/var/log/httpd/error_log
中有以下行:然后我运行了以下两个命令行:
它再次起作用 .