0

I have a Django app which is deployed in local network using Apache + mod_wsgi under Windows. When I run python manage.py runserver, everything works fine. But when I start the Apache Service, I cannot access the app. The only response I get from the access.log is the error code 408. Below is my httpd.conf:

LoadFile "c:/users/felix/appdata/local/programs/python/python37/python37.dll"
LoadModule wsgi_module "c:/users/felix/appdata/local/programs/python/python37/lib/site-packages/mod_wsgi/server/mod_wsgi.cp37-win_amd64.pyd"
WSGIPythonHome "c:/users/felix/appdata/local/programs/python/python37"

ServerName localhost

WSGIScriptAlias / "D:/dev/test_server/django/django/wsgi_windows.py"
Listen 8000
<VirtualHost *:8000>
    WSGIPassAuthorization On
    ErrorLog "logs/django.error.log"
    CustomLog "logs/django.access.log" combined

    Alias /static "D:/dev/test_server/staticfiles"
    <Directory "D:/dev/test_server/staticfiles">
        Require all granted
    </Directory>

    <Directory "D:/dev/test_server/django/django">
        <Files wsgi_windows.py>
            Require all granted
        </Files>
    </Directory>

    <Directory />
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

And below is the wsgi_windows.py file:

# Activate the virtualenv
activate_this = 'D:/dev/test_server/.venv/Scripts/activate_this.py'
exec(open(activate_this).read(), dict(__file__=activate_this))

import os  # noqa
import sys  # noqa
import site  # noqa

# Add the site-packages of the chosen virtualenv to work with
site.addsitedir('D:/dev/test_server/.venv/Lib/site-packages')

# Add the app's directory to the PYTHONPATH
sys.path.append('D:/dev/test_server/django')
sys.path.append('D:/dev/test_server/django/django')

os.environ['DJANGO_SETTINGS_MODULE'] = 'django.settings'
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django.settings")

from django.core.wsgi import get_wsgi_application  # noqa
application = get_wsgi_application()

I'd appreciate any ideas or hints on the issue.

2
  • Best place to start is to check the apache log files Make sure URL u are requesting is there in ur urls.py and u can access it through the local run (runserver) Good luck Commented Dec 22, 2020 at 15:53
  • @octopus The command python manage.py runserver works just fine. Every url are working. The log files in Apache doesn't give any further info except 408 code. Commented Dec 22, 2020 at 17:14

2 Answers 2

2
  1. start apache at command line with 'httpd' and look for error messages. If Apache has a problem at startup there is no message in the log files.
  2. check error.log You can place 'print('xyz') even in the settings.py and elsewhere and this way by checking error.log see how your app is setup and how far a request is processed. If your app get stuck somewhere like this you find the code where it is stuck
Sign up to request clarification or add additional context in comments.

3 Comments

Well thank you for the hint. It's funny that there is no messages in log files if Apache has a problem. But yeah, I placed print-functions in the settings.py and these strings are shown in error.log in the Apache logs folder. So I guess the problem is not in my project settings. Any idea which other files are run at startup? I also placed print-function in my app's views.py but it wasn't shown in the error.log.
Ok so Apache is running and your django app settings is started and 408 means timeout so your app does not return within the timeout of Apache. Please check in httpd.conf if the TimeOut is accidentally short (sorry I dont know the default...google or put a high value to test. Please in your settings.py put DEBUG=True and call your page. Errors? Please Post urls.py settings.py and views.py
Hello, so as it turns out, Apache had a problem with the current numpy version. I'm not really sure why it has a problem, since running python manage.py runserver does not err. But yeah, currently installing numpy 1.16.0 does the trick. Thank you again.
1

I have the same error after install scipy library and use it in some scrip in django. I found that some libraries like "numpy" and "scipy" only work in the Python main interpreter and you have to force the WSGI to run in the global app group to run it. Adding this line in my conf file work for me.

WSGIApplicationGroup %{GLOBAL}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.