Pregunta

I am trying to make my django project work with httpd using mod_wsgi. But I keep getting a "500 Internal Server Error". I am using a PostgreSQL Postgis database. My OS is Fedora 20.

What is really weird is that :

  • The project works just fine when I use Django development Server instead of httpd.
  • It also works fine when I use something other than Postgis, i.e. when I replace the followig line in the file settings.py :

    'ENGINE': 'django.contrib.gis.db.backends.postgis',

    by any other database (mysql, sqlite3..), such as :

    'ENGINE': 'django.db.backends.mysql',

Here is my httpd configuration file for the django project (let's say it is called testproject) (I put this file in /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>

The part of the project settings (settings.py) that is apparently generating the error:

DATABASES = {
    'default': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',
        'NAME': 'db_name',                      
        'USER': 'db_user',                      
        'PASSWORD': '',                  
        'HOST': '',                      
        'PORT': '',                     
    }
}

When I try to access the URL testproject.com, I get a "500 Internal Server Error", and the httpd error log is the following:

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

I insist on the fact that this error is only happening using django.contrib.gis.db.backends.postgis, but it's working fine using any of the django.db.backends.*.

Any help or idea would be greatly appreciated.

¿Fue útil?

Solución

I just found where the problem was. It was coming from SELinux policy that was apparently denying the permission for httpd to access the page.

I had in my /var/log/httpd/error_log the following line:

[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

Then I ran the two following command lines:

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

And it worked again.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top