Lexinton Ave Lexinton Ave - 3 years ago 179
Apache Configuration Question

Why apache with mod_wsgi timed out?

I was using apache with mod_wsgi to deploy my django project. What I did was:

  1. python manage.py startproject mysite
    as the django tutorial guides,

  2. add to apache conf/httpd.conf the following configuration:

    ServerName www.example.com
    ServerAlias example.com
    ServerAdmin webmaster@example.com

    WSGIDaemonProcess example.com processes=2 threads=15 display-name=%{GROUP} python-path=/root/mysite python-home=/usr
    WSGIProcessGroup example.com

    WSGIScriptAlias / /root/mysite/mysite/wsgi.py

    <Directory /root/mysite/mysite>
    Require all granted

  3. type example.com in the address bar, then get time out response:

    Gateway Timeout

    The gateway did not receive a timely response from the upstream server or application.

How to handle this time-out in case of just a toy django app? I think it's not related to performance issues, but might be caused by some misconfiguration. Could anyone help? Thanks!

Answer Source

You don't need:


as you are using the system Python. You only need that if using a Python virtual environment.

Now add:

WSGIApplicationGroup %{GLOBAL}

and see if that changes anything. It shouldn't if this is a brand new Django project, but if you have changed it and are importing certain Python packages that don't work in Python sub interpreters, you will need that.

Also check the Apache error log as it will give you a more precise reason as to why the timeout occurred.


If you compiled mod_wsgi yourself and want it to use /usr/local/python3 for the Python installation, you will need to add:

WSGIPythonHome /usr/local/python3

just after the LoadModule line for wsgi_module. This is very important if you also have a system Python installation for version 3.6.

You also need to check whether it is picking up the correct shared library. Use ldd as explained in:

to see what Python shared library it is picking up and whether it is find that under /usr/local/python3/lib or not. If it is picking up one from /usr/lib that will cause issues.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download