Issue
I've worked on a Django project locally and everything was working fine.
I deployed it on EC2 Ubuntu instance alongwith Apache2 and it is giving a server error 500. I've tried with gunicorn+nginx as well, still no joy.
So as a context, I'm using Django4, Python3, Apache2 alongwith;
- AWS RDS for postgres DB
- AWS S3 for static files (Both are working fine in dev and prod mode locally).
I've also added my EC2 IP address to ALLOWED_HOSTS and still the same (also getting same error if I allowed everything by *).
Note: I've all my credentials in .env file.
Somehow the Django application isn't providing access.
I actually want to get an SSL from CertBot and assign my purchased .dev domain.
I'm actually stuck here for past couple of days, gone though several blogs but not able to get this resolved.
Any suggestions would be of massive help.
Thanks.
my apache .conf file
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName <aws_public_ip_address>
ServerAlias <aws_public_ip_address>
DocumentRoot /home/ubuntu/liveProject/Django-Project
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /static /home/ubuntu/liveProject/Django-Project/static
<Directory /home/ubuntu/liveProject/Django-Project/static>
Require all granted
</Directory>
Alias /template /home/ubuntu/liveProject/Django-Project/tempate
<Directory /home/ubuntu/liveProject/Django-Project/tempate>
Require all granted
</Directory>
<Directory /home/ubuntu/liveProject/Django-Project/ProjectName>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess Django-Project python-path=/home/ubuntu/liveProject/Django-Project python-home=/home/ubuntu/liveProject/liveEnv
WSGIProcessGroup Django-Project
WSGIScriptAlias / /home/ubuntu/liveProject/Django-Project/ProjectName/wsgi.py
</VirtualHost>
Thanks.
UPDATE: Error log with Debug = False
[Fri Apr 15 12:36:03.370447 2022] [mpm_event:notice] [pid 35855:tid 139942111996992] AH00489: Apache/2.4.41 (Ubuntu) OpenSSL/1.1.1f mod_wsgi/4.6.8 Python/3.8 configured -- resuming normal operations
[Fri Apr 15 12:36:03.370541 2022] [core:notice] [pid 35855:tid 139942111996992] AH00094: Command line: '/usr/sbin/apache2'
Error log with Debug = True
Exception ignored in: <function Local.__del__ at 0x7fd92c735700>
Traceback (most recent call last):
File "/home/ubuntu/liveProject/liveEnv/lib/python3.8/site-packages/asgiref/local.py", line 96, in __del__
NameError: name 'TypeError' is not defined
Exception ignored in: <function Local.__del__ at 0x7fd92c735700>
Traceback (most recent call last):
File "/home/ubuntu/liveProject/liveEnv/lib/python3.8/site-packages/asgiref/local.py", line 96, in __del__
NameError: name 'TypeError' is not defined
access.log
<my_ip> - - [15/Apr/2022:12:39:28 +0000] "GET / HTTP/1.1" 400 5208 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36"
<my_ip> - - [15/Apr/2022:12:39:48 +0000] "-" 408 4737 "-" "-"
<my_ip> - - [15/Apr/2022:12:39:48 +0000] "-" 408 4737 "-" "-"
<my_ip> - - [15/Apr/2022:12:40:33 +0000] "GET / HTTP/1.1" 400 5208 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36"
49.14.87.5 - - [15/Apr/2022:12:40:36 +0000] "GET / HTTP/1.1" 400 794 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36"
<my_ip> - - [15/Apr/2022:12:40:56 +0000] "-" 408 323 "-" "-"
<aws_ip> - - [15/Apr/2022:12:40:56 +0000] "-" 408 4737 "-" "-"
<aws_ip> - - [15/Apr/2022:12:41:14 +0000] "GET / HTTP/1.1" 400 5209 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.83 Safari/537.1"
<aws_ip> - - [15/Apr/2022:12:41:34 +0000] "GET / HTTP/1.1" 301 580 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.83 Safari/537.1"
<aws_ip> - - [15/Apr/2022:12:41:56 +0000] "-" 408 4738 "-" "-"
Solution
I've identified the problem and it is FIXED now, finally after more than 2 days.
It was nothing, the apache or the django wasn't populating values from my .env file. It was like the .env file doesn't exit.
I replaced every value directly to settings.py and it worked.
I'll now have to see how I could define my sensitive credentials away from settings.py
Thanks.
Answered By - fortyseven Answer Checked By - Gilberto Lyons (WPSolving Admin)