【问题标题】:Django with mod_wsgi doesn't work with Postgis带有 mod_wsgi 的 Django 不适用于 Postgis
【发布时间】:2014-06-29 20:00:27
【问题描述】:

我正在尝试使用 mod_wsgi 使我的 django 项目与 httpd 一起工作。但我不断收到“500 内部服务器错误”。我正在使用 PostgreSQL Postgis 数据库。我的操作系统是 Fedora 20。

真正奇怪的是:

  • 当我使用 Django 开发服务器而不是 httpd 时,该项目运行良好。
  • 当我使用 Postgis 以外的东西 时,它也可以正常工作,即当我替换文件 settings.py 中的后续行时:

    '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.* 都可以正常工作。

任何帮助或想法将不胜感激。

【问题讨论】:

  • 您最好将找到的解决方案发布为答案,然后接受它
  • 好的,我现在不能这样做(我的声望不到 10,所以我必须等待 8 小时才能回复我自己的帖子)但我会尽快这样做可以。

标签: django apache mod-wsgi postgis selinux


【解决方案1】:

我刚刚发现问题出在哪里。它来自 SELinux 政策,显然拒绝了 httpd 访问该页面的权限。

我的/var/log/httpd/error_log 中有以下行:

[Mon May 12 14:04:34.876392 2014] [core:notice] [pid 20070] SELinux policy enabled; httpd running as context system_u:system_r:httpd_t:s0

然后我运行了以下两个命令行:

sudo grep httpd /var/log/audit/audit.log | audit2allow -M mypol
sudo semodule -i mypol.pp

它又起作用了。

【讨论】:

    猜你喜欢
    • 2016-05-26
    • 2020-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-02
    • 1970-01-01
    • 1970-01-01
    • 2012-04-30
    相关资源
    最近更新 更多