Internal Server Error

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at webmaster@localhost to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.

Apache/2.4.52 (Ubuntu) Server at 172.105.13.229 Port 80

sudo tail -f /var/log/apache2/error.log

[Sun Oct 29 23:34:47.448181 2023] [wsgi:error] pid 202541:tid 140616591717952The timeout specified has expired: [client 99.255.136.241:46142] mod_wsgi (pid=202541): Failed to proxy response from daemon.
[Sun Oct 29 23:34:51.632303 2023] [wsgi:error] [pid 202541:tid 140616457434688] [client 143.110.222.166:46360] Truncated or oversized response headers received from daemon process 'django_app': /home/jsandor/src/django_project/wsgi.py
[Sun Oct 29 23:34:51.633131 2023] [wsgi:error] [pid 202541:tid 140616474220096] [client 99.255.136.241:57972] Truncated or oversized response headers received from daemon process 'django_app': /home/jsandor/src/django_project/wsgi.py, referer: http://172.105.13.229/
[Sun Oct 29 23:34:51.633522 2023] [wsgi:error] [pid 202541:tid 140616482612800] [client 99.255.136.241:32782] Truncated or oversized response headers received from daemon process 'django_app': /home/jsandor/src/django_project/wsgi.py, referer: http://172.105.13.229/
[Sun Oct 29 23:34:51.633894 2023] [wsgi:error] [pid 202541:tid 140616507790912] [client 99.255.136.241:41828] Truncated or oversized response headers received from daemon process 'django_app': /home/jsandor/src/django_project/wsgi.py, referer: http://172.105.13.229/
[Sun Oct 29 23:34:51.634272 2023] [wsgi:error] [pid 202541:tid 140616524576320] [client 99.255.136.241:53360] Truncated or oversized response headers received from daemon process 'django_app': /home/jsandor/src/django_project/wsgi.py, referer: http://172.105.13.229/
[Sun Oct 29 23:34:51.634619 2023] [wsgi:error] [pid 202541:tid 140616532969024] [client 99.255.136.241:38868] Truncated or oversized response headers received from daemon process 'django_app': /home/jsandor/src/django_project/wsgi.py, referer: http://172.105.13.229/
[Sun Oct 29 23:34:51.635044 2023] [wsgi:error] [pid 202541:tid 140616541361728] [client 99.255.136.241:38852] Truncated or oversized response headers received from daemon process 'django_app': /home/jsandor/src/django_project/wsgi.py, referer: http://172.105.13.229/

Any suggestions?

4 Replies

Looking back at those error logs you shared, here's what I think is going on:

The main errors seem to be:

  • Failed proxy response from the mod_wsgi daemon process - likely a config issue with mod_wsgi
  • Oversized response headers from the Django app - could be bad header settings in Django views/middleware

Alright, here are some steps I'd recommend to troubleshoot and fix these issues:
1 . Restart Apache and Django app to clear any bad state:

sudo systemctl restart apache2 # restart Apache 
sudo systemctl restart gunicorn # or whatever you use to run Django

2 . Check mod_wsgi config:

  • Make sure WSGIDaemonProcess points to wsgi.py.
  • Verify WSGIScriptAlias also points to wsgi.py.
  • Set WSGIPythonPath if needed.

3 . Turn on mod_wsgi logging to check for errors:

LogLevel info  
WSGILog /var/log/apache2/wsgi.log # log errors here

4 . Test Django standalone to see if it works:

python manage.py runserver # run dev server

5 . If Django works alone, focus on mod_wsgi. If not, look at Django app.

6 . Check middleware/views setting headers in Django. No huge headers.

7 . Try simple stuff wsgi.py that just returns "Hello World". Get that working through mod_wsgi first.

8 . Try adding limiting on IP's like 99.255.136.241 making excessive requests.

Check other logs for clues. Tweak configs accordingly. Taking it step-by-step to isolate where issues arise, then gradually building back up the config often helps pinpoint and fix specific problems.

The last time the site worked perfectly is when I ran:
python manage.py runserver 0.0.0.0:8000 (I left port 8000 open!)
After that I ran the following commands:
sudo apt-get install apache2
sudo apt-get install libapache2-mod-wsgi-py3
cd /etc/apache2/sites-available/
sudo cp 000-default.conf src.conf
sudo nano src.conf
Apache Server Conf.:
Alias /static /home/jsandor/src/static
<directory home="" jsandor="" src="" static=""> Require all granted </directory>

     Alias /media /home/jsandor/src/media
     <Directory /home/jsandor/src/media>
             Require all granted
     </Directory>

     <Directory /home/jsandor/src/django_project>
             <Files wsgi.py>
                     Require all granted
             </Files>
     </Directory>

     WSGIScriptAlias / /home/jsandor/src/django_project/wsgi.py
     WSGIDaemonProcess django_app python-path=/home/jsandor/src   python-home=/home/jsandor/src/venv
     WSGIProcessGroup django_app


sudo a2ensite src
sudo a2dissite 000-default.conf
systemctl reload apache2
sudo chown :www-data src/db.sqlite3
sudo chmod 664 src/db.sqlite3
sudo chown :www-data src/
sudo chown -R :www-data src/media
sudo chmod -R 775 src/media

Does anything stick out as a mistake, or if I need to install additional software?
Thanks.

Alias /static /home/jsandor/src/static
<directory home="" jsandor="" src="" static=""> Require all granted </directory>

Sorry! The Alias /static did not paste correctly. It is in the same format as Alias /media above.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct