Невозможно получить ответ на более чем первый или несколько первых запросов с помощью Django и Apache?

I have started to learn Python, then Django in 
practice by way of executing tutorial codes in Python 
IDLE.
Indeed as maybe the code is of old versions the code
running not always works well.
Especially I am stacked upon running Django with 
Apache 2.4 through mod_wsgi.
I have done it at first two-three weeks ago, and then 
main issue was that Django requests on apache (on 
localhost, not on built-in localhost:8000)
completed normally just the two-three times, then I 
should wait almost indefinitely
to see the response from request, or without it.
This week I returned to this example Django plus 
Apache, but it detiorated to the
level that just first request is done, the second one 
almost not executed in a moment
as it should be, or even not at all, the next ones - 
not at all untill Apache server restart 
in Apache24\bin httpd command.
I have extracted Apache lounge (on Windows 10) in 
C:\Apache24 folder as it should be.
Indeed when extracting I deleted two files 
(readme.txt..)as evidently not neccesarily files over 
nested Apache24 folder, so maybe I should extract to 
C:\Apache24\Apache24. When I extracted to the nested 
folder ---
and run from C:\Apache24\Apache24\bin -- the situation 
the same.
I use Python 3.10.5, Django==4.2.11, mod_wsgi-4.9.2- 
cp310-cp310-win_amd64.whl,
Apache/2.4.58 (Win64) Apache Lounge VS17 Server built.
Django project/app is in virtual environment and all 
request almost works well with native django server.

here is my django configuration:
*settings.py:*

DEBUG = False # с DEBUG = True - тот же результат ALLOWED_HOSTS = ['localhost', '127.0.0.1'] #ALLOWED_HOSTS = ['localhost','*', '127.0.0.1'] - то же самое

 ---wsgi.py:*
import os
import sys
from django.core.wsgi import get_wsgi_application
from pathlib import Path

# Add project directory to the sys.path
path_home = str(Path(__file__).parents[1])
if path_home not in sys.path:
    sys.path.append(path_home)
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'my_tennis_club.settings')
application = get_wsgi_application()
Indeed without it with initial wsgi.py configuration worked probably not worst:

import os
from django.core.wsgi import get_wsgi_application os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'my_tennis_club.settings')
приложение = get_wsgi_application()

But first thing before wsgi.py config I did I tried Apache config for django by next sites:

https://montesariel.com/blog/post-3 https://dev.to/willmvs/flask-deployment-on-windows-139b https://medium.com/@deepankaracharyya/deploying-a-django-app-with-apache-mod-wsgi-windows-e9712dc07bba https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/modwsgi/#using-a-virtualenv

My first configuarion was such one I put in the end of httpd.conf file:
LoadFile "C:/Program Files/Python/Python310/python310.dll" 
LoadModule wsgi_module "C:/pythons/myworld/lib/site-packages/mod_wsgi/server/mod_wsgi.cp310-win_amd64.pyd"
WSGIScriptAlias / "C:/pythons/myworld/my_tennis_club/my_tennis_club/wsgi.py"
WSGIPythonHome "C:/pythons/myworld" 
WSGIPythonPath "C:/pythons/myworld/my_tennis_club"
<Directory "C:/pythons/myworld/my_tennis_club">    
   <Files wsgi.py>
      Require all granted    
   </Files> 
</Directory>
(These LoadFile, LoadModule, WSGIPythonHome strings I 
get by running
"mod_wsgi-express module-config command" in cmdline in 
django project directory when virtenv is activated -
so mod_wsgi is installed probably corectly).

At that time I could do at least two-three requests- 
response not just one as for now.
Maybe it worked even without this config and wsgi.py 
config that I did later.
Then I included second apache config instead first one 
in httpf.conf:
LoadFile "C:/Program Files/Python/Python310/python310.dll" 
LoadModule wsgi_module "C:/pythons/myworld/lib/site-packages/mod_wsgi/server/mod_wsgi.cp310-win_amd64.pyd"
WSGIPythonHome "C:/pythons/myworld" 
WSGIPythonPath "C:/pythons/myworld/my_tennis_club"
<VirtualHost *:80>
  ServerName localhost
  WSGIScriptAlias / "C:/pythons/myworld/my_tennis_club/my_tennis_club/wsgi.py"    
 <Directory "C:/pythons/myworld/my_tennis_club">
   <Files wsgi.py>
     Require all granted
   </Files>
 </Directory>
 ErrorLog "C:/pythons/myworld/my_tennis_club/my_tennis_club/error.log"
 CustomLog "C:/pythons/myworld/my_tennis_club/my_tennis_club/access.log" combined
</VirtualHost>
Indeed in error.log (or to be precise in access.log), 
as in the same Apache logs files,  I have noted 
recently 408 Request Timeout status code.
Here is latest Apache error.log by first config:
AH00558: httpd: Could not reliably determine the servers  fully qualified domain name, using fe80::adbf:d08d:89cd:c15b. Set the 'ServerName' directive globally to suppress this message
[Sat Apr 27 16:04:24.843298 2024] [mpm_winnt:notice] [pid 12740:tid 400] AH00354: Child: Starting 64 worker threads.
[Sat Apr 27 16:04:25.799255 2024] [mpm_winnt:notice] [pid 1704:tid 432] AH00364: Child: All worker threads have exited.
[Sat Apr 27 16:04:32.799261 2024] [mpm_winnt:notice] [pid 4692:tid 396] AH00422: Parent: Received shutdown signal -- Shutting down the server.
[Sat Apr 27 16:04:34.938465 2024] [mpm_winnt:notice] [pid 12740:tid 400] AH00364: Child: All worker threads have exited.
[Sat Apr 27 16:04:34.979333 2024] [mpm_winnt:notice] [pid 4692:tid 396] AH00430: Parent: Child process 12740 exited successfully.
[Sat Apr 27 16:04:44.915552 2024] [mpm_winnt:notice] [pid 1656:tid 428] AH00362: Child: Waiting 30 more seconds for 4 worker threads to finish.
[Sat Apr 27 16:05:17.409754 2024] [mpm_winnt:notice] [pid 1656:tid 428] AH00362: Child: Waiting 0 more seconds for 4 worker threads to finish.
[Sat Apr 27 16:05:17.517517 2024] [mpm_winnt:notice] [pid 1656:tid 428] AH00363: Child: Terminating 4 threads that failed to exit.
[Sat Apr 27 16:05:17.517517 2024] [mpm_winnt:notice] [pid 1656:tid 428] AH00364: Child: All worker threads have exited.

I need click Ctrl+C and Ctrl+BREAK several times to 
stop server predominantly.
And when starting, there is such notification that 
there is no server domain name defined.
When I uncomment and put "ServerName localhost:80" in 
Apache httpd.config -- server even cannot start.
I used this guide for Apache install: 
https://mid.as/kb/00143/install-configure-apache-on- 
windows except last configs (Add "ExecCGI" to 
"Options" directive...). But after applying it nothing 
changes.

In access.log file I see:
::1 - - [26/Apr/2024:01:18:12 +0300] "-" 408 -
::1 - - [26/Apr/2024:01:29:09 +0300] "-" 408 -
::1 - - [27/Apr/2024:14:58:35 +0300] "-" 408 -
But for two-three weeks ago I also see such lines as:
::1 - - [07/Apr/2024:21:23:53 +0300] "GET /connection/ HTTP/1.1" 200 1193
::1 - - [07/Apr/2024:21:24:03 +0300] "POST /login/ HTTP/1.1" 200 90

As well I have noted that Django forms page did not 
render even as first request so probably
it needs static files Apache config indeed I used 
whitenoise middleware before it.

So I do not know what I should do that django would 
work with apache (not first request or first requests)
What part of config is not correct? What maybe 
interfers with these requests and do not allow to 
complete response?
I have checked that 80 port is not occupied when Apache server is not started.
Вернуться на верх