Trying to Fix Django AWS 500 Internal Error I got two more errors Access Log: Permission Denied and Website Does not Load Static

:warning: IMPORTANT, please fill the questions

We assume you are using Bitnami to deploy your application.

  • Which version of the application are you using?:
    Django

  • Please choose how you got the application: Installer (Windows, Linux, macOS), cloud image (AWS, GCE, Azure, …) or VM (VMDK, VBOX):
    AWS

  • Have you installed any plugin or modified any configuration file?:
    I followed the tutorial to configure apache server to keep my website running but no success

  • Describe here your question/suggestion/issue (expected and actual results):
    Trying to Fix Django AWS 500 Internal Error I got two more errors Access Log: Permission Denied and Website Does not Load Static

I followed this totorial https://aws.amazon.com/getting-started/hands-on/deploy-python-application/
website is running on 8000 port when I run paython manage.py runserver 0.0.0.0:8000 but it shuts down when I close the terminal

I tried to debug apache https://docs.bitnami.com/google/infrastructure/django/troubleshooting/debug-errors-apache/
When I restart apache I receive syntax ok
nothing is running on 8000 port

while trying to fix things
I got new two issues
when I type /opt/bitnami/apache2/logs/error_log I receive Permission denied
The website including admin do not load static files when I run paython manage.py runserver 0.0.0.0:8000

  • Steps to reproduce the issue (if relevant):

  • Copy the apache log (if relevant):

PASTE HERE

Is there a way to edit my post?

Hi @Majali,

Thanks for using Bitnami. Can you check if following our guide solves your issue?

https://docs.bitnami.com/aws/infrastructure/django/get-started/start-django-project/

Also, we have a Support Tool that will gather relevant information for us to analyze your configuration and logs. Could you please execute it on the machine where the stack is running by following the steps described in the guide below?

Please note that you need to paste the code ID that is shown at the end.

For the edit button, if you click the “three dots” button in your post

It will show you another “pencil” button to edit it

Hi gongomgra

Thank you for your reply and for your help, I will check them write now

Thank you again
I do not know why I don’t have the pencil, I use firefox

Good morning Gongomgra,
I run the Bitnami support tool and here is the code
b761cd80-8da7-40ed-e45a-2201f15a4dbb

Hi @Majali,

Thanks for the bnsupport bundle. I found the next error in the Apache log file

[Mon Apr 13 16:58:19.616793 2020] [wsgi:error] [pid 3165] [remote 188.163.97.81:62913] Invalid HTTP_HOST header: '18.195.166.105'. You may need to add '18.195.166.105' to ALLOWED_HOSTS.
[Tue Apr 14 14:30:29.008570 2020] [wsgi:error] [pid 2639] [client 188.163.97.81:62740] mod_wsgi (pid=2639): Failed to exec Python script file '/opt/bitnami/apps/django/django_projects/lewhdk/lewhdk/wsgi.py'.
[Tue Apr 14 14:30:29.008630 2020] [wsgi:error] [pid 2639] [client 188.163.97.81:62740] mod_wsgi (pid=2639): Exception occurred processing WSGI script '/opt/bitnami/apps/django/django_projects/lewhdk/lewhdk/wsgi.py'.
[Tue Apr 14 14:30:29.012222 2020] [wsgi:error] [pid 2639] [client 188.163.97.81:62740] Traceback (most recent call last):
[Tue Apr 14 14:30:29.012277 2020] [wsgi:error] [pid 2639] [client 188.163.97.81:62740]   File "/opt/bitnami/apps/django/django_projects/lewhdk/lewhdk/wsgi.py", line 16, in <module>
[Tue Apr 14 14:30:29.012284 2020] [wsgi:error] [pid 2639] [client 188.163.97.81:62740]     application = get_wsgi_application()
[Tue Apr 14 14:30:29.012291 2020] [wsgi:error] [pid 2639] [client 188.163.97.81:62740]   File "/opt/bitnami/apps/django/lib/python3.7/site-packages/Django-2.2.9-py3.7.egg/django/core/wsgi.py", line 12, in get_wsgi_application
[Tue Apr 14 14:30:29.012295 2020] [wsgi:error] [pid 2639] [client 188.163.97.81:62740]     django.setup(set_prefix=False)
[Tue Apr 14 14:30:29.012302 2020] [wsgi:error] [pid 2639] [client 188.163.97.81:62740]   File "/opt/bitnami/apps/django/lib/python3.7/site-packages/Django-2.2.9-py3.7.egg/django/__init__.py", line 24, in setup
[Tue Apr 14 14:30:29.012306 2020] [wsgi:error] [pid 2639] [client 188.163.97.81:62740]     apps.populate(settings.INSTALLED_APPS)
[Tue Apr 14 14:30:29.012312 2020] [wsgi:error] [pid 2639] [client 188.163.97.81:62740]   File "/opt/bitnami/apps/django/lib/python3.7/site-packages/Django-2.2.9-py3.7.egg/django/apps/registry.py", line 91, in populate
[Tue Apr 14 14:30:29.012316 2020] [wsgi:error] [pid 2639] [client 188.163.97.81:62740]     app_config = AppConfig.create(entry)
[Tue Apr 14 14:30:29.012322 2020] [wsgi:error] [pid 2639] [client 188.163.97.81:62740]   File "/opt/bitnami/apps/django/lib/python3.7/site-packages/Django-2.2.9-py3.7.egg/django/apps/config.py", line 90, in create
[Tue Apr 14 14:30:29.012326 2020] [wsgi:error] [pid 2639] [client 188.163.97.81:62740]     module = import_module(entry)
[Tue Apr 14 14:30:29.012332 2020] [wsgi:error] [pid 2639] [client 188.163.97.81:62740]   File "/opt/bitnami/python/lib/python3.7/importlib/__init__.py", line 127, in import_module
[Tue Apr 14 14:30:29.012336 2020] [wsgi:error] [pid 2639] [client 188.163.97.81:62740]     return _bootstrap._gcd_import(name[level:], package, level)
[Tue Apr 14 14:30:29.012341 2020] [wsgi:error] [pid 2639] [client 188.163.97.81:62740]   File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
[Tue Apr 14 14:30:29.012354 2020] [wsgi:error] [pid 2639] [client 188.163.97.81:62740]   File "<frozen importlib._bootstrap>", line 983, in _find_and_load
[Tue Apr 14 14:30:29.012361 2020] [wsgi:error] [pid 2639] [client 188.163.97.81:62740]   File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
[Tue Apr 14 14:30:29.012378 2020] [wsgi:error] [pid 2639] [client 188.163.97.81:62740] ModuleNotFoundError: No module named 'notifications'

It looks like you are not able to access your Django project because the ALLOWE_HOSTS for the project is not properly set. It also look like your project is missing some pip dependencies. Were you able to follow our official guide I posted in a previous message?

Once you have Django project created using that guide, you can configure Apache follow the next one

https://docs.bitnami.com/aws/infrastructure/django/get-started/deploy-django-project/#production

Hi @gongomgra
Thank you for your help

I am not sure if this report is up to date as you see
[Mon Apr 13 16:58:19.616793 2020] Invalid HTTP_HOST header: ‘18.195.166.105’. You may need to add ‘18.195.166.105’ to ALLOWED_HOSTS.

[Tue Apr 14 14:30:29.012378 2020] ModuleNotFoundError: No module named ‘notifications’

These records are three and two days ago, before I create this post/ticket
This means no Apache server errors last two days, please, correct me if otherwise

The website runs on 8000 port without issues, I attach an image

Regrading the static files it happens when debug is false which is another problem I will try to solve it later on
but now my biggest problem is keeping the website running using apache

Do you want me to send/write the code of the files wsgi.py httpd-app.conf httpd-prefix.conf bitnami.conf ?

I have no experience working neither with apache nor with wsgi

Thank you

Hi @Majali,

I posted the error messages I found in the bnsupport bundle you send us. Can you check the logs in case you find similar messages in more recent dates?

Apart from that, I think your Apache service (running under the user daemon) can’t access them. Can you try running the command below? Replace YOUR_PROJECT with the correct name

sudo chown -R bitnami:daemon /opt/bitnami/apps/django/django_projects/YOUR_PROJECT

After that, restart all services and try again.

Hi @gongomgra
Thank you for your help

I tried the code you wrote to me

sudo chown -R bitnami:daemon /opt/bitnami/apps/django/django_projects/lewhdk

sudo /opt/bitnami/ctlscript.sh restart apache

Rebooted the instance

/opt/bitnami/apache2/logs/error_log

I still get “Permission denied”

I could access the error_log file using Filezilla
Here is what I receive every time I try to access the website
[Fri Apr 17 13:45:17.871421 2020] [wsgi:error] [pid 2191] [client 5.101.0.209:43444] mod_wsgi (pid=2191): Failed to exec Python script file ‘/opt/bitnami/apps/django/django_projects/lewhdk/lewhdk/wsgi.py’.
[Fri Apr 17 13:45:17.871474 2020] [wsgi:error] [pid 2191] [client 5.101.0.209:43444] mod_wsgi (pid=2191): Exception occurred processing WSGI script ‘/opt/bitnami/apps/django/django_projects/lewhdk/lewhdk/wsgi.py’.
[Fri Apr 17 13:45:17.871586 2020] [wsgi:error] [pid 2191] [client 5.101.0.209:43444] Traceback (most recent call last):
[Fri Apr 17 13:45:17.871621 2020] [wsgi:error] [pid 2191] [client 5.101.0.209:43444] File “/opt/bitnami/apps/django/django_projects/lewhdk/lewhdk/wsgi.py”, line 7, in
[Fri Apr 17 13:45:17.871626 2020] [wsgi:error] [pid 2191] [client 5.101.0.209:43444] application = get_wsgi_application()
[Fri Apr 17 13:45:17.871633 2020] [wsgi:error] [pid 2191] [client 5.101.0.209:43444] File “/opt/bitnami/apps/django/lib/python3.7/site-packages/Django-2.2.9-py3.7.egg/django/core/wsgi.py”, line 12, in get_wsgi_application
[Fri Apr 17 13:45:17.871637 2020] [wsgi:error] [pid 2191] [client 5.101.0.209:43444] django.setup(set_prefix=False)
[Fri Apr 17 13:45:17.871642 2020] [wsgi:error] [pid 2191] [client 5.101.0.209:43444] File “/opt/bitnami/apps/django/lib/python3.7/site-packages/Django-2.2.9-py3.7.egg/django/init.py”, line 24, in setup
[Fri Apr 17 13:45:17.871646 2020] [wsgi:error] [pid 2191] [client 5.101.0.209:43444] apps.populate(settings.INSTALLED_APPS)
[Fri Apr 17 13:45:17.871652 2020] [wsgi:error] [pid 2191] [client 5.101.0.209:43444] File “/opt/bitnami/apps/django/lib/python3.7/site-packages/Django-2.2.9-py3.7.egg/django/apps/registry.py”, line 83, in populate
[Fri Apr 17 13:45:17.871656 2020] [wsgi:error] [pid 2191] [client 5.101.0.209:43444] raise RuntimeError(“populate() isn’t reentrant”)
[Fri Apr 17 13:45:17.871683 2020] [wsgi:error] [pid 2191] [client 5.101.0.209:43444] RuntimeError: populate() isn’t reentrant
[Fri Apr 17 13:51:14.454765 2020] [mpm_prefork:notice] [pid 2181] AH00169: caught SIGTERM, shutting down
[Fri Apr 17 13:51:18.329469 2020] [ssl:warn] [pid 2975] AH01873: Init: Session Cache is not configured [hint: SSLSessionCache]
[Fri Apr 17 13:51:18.351131 2020] [mpm_prefork:notice] [pid 2975] AH00163: Apache/2.4.41 (Unix) OpenSSL/1.1.1d mod_wsgi/4.6.7 Python/3.7 configured – resuming normal operations
[Fri Apr 17 13:51:18.351161 2020] [core:notice] [pid 2975] AH00094: Command line: ‘/opt/bitnami/apache2/bin/httpd.bin -f /opt/bitnami/apache2/conf/httpd.conf’
[Fri Apr 17 13:51:30.899440 2020] [mpm_prefork:notice] [pid 2975] AH00169: caught SIGTERM, shutting down
[Fri Apr 17 13:52:50.750753 2020] [ssl:warn] [pid 1966] AH01873: Init: Session Cache is not configured [hint: SSLSessionCache]
[Fri Apr 17 13:52:50.767790 2020] [mpm_prefork:notice] [pid 1966] AH00163: Apache/2.4.41 (Unix) OpenSSL/1.1.1d mod_wsgi/4.6.7 Python/3.7 configured – resuming normal operations
[Fri Apr 17 13:52:50.767819 2020] [core:notice] [pid 1966] AH00094: Command line: ‘/opt/bitnami/apache2/bin/httpd.bin -f /opt/bitnami/apache2/conf/httpd.conf’

Here is the code of wsgi.py file
import os
import sys
sys.path.append(’/opt/bitnami/apps/django/django_projects/lewhdk’)
os.environ.setdefault(“PYTHON_EGG_CACHE”, “/opt/bitnami/apps/django/django_projects/lewhdk/egg_cache”)
os.environ.setdefault(“DJANGO_SETTINGS_MODULE”, “lewhdk.settings”)
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

And here is the code of httpd-app.cof file
<IfDefine !IS_DJANGOSTACK_LOADED>
Define IS_DJANGOSTACK_LOADED
WSGIDaemonProcess wsgi-djangostack processes=2 threads=15 display-name=%{GROUP}

<Directory “/opt/bitnami/apps/django/django_projects/lewhdk/lewhdk”>
Options +MultiViews
AllowOverride All
= 2.3>
Require all granted

WSGIProcessGroup wsgi-djangostack

WSGIApplicationGroup %{GLOBAL}

Alias /lewhdk/static “/opt/bitnami/apps/django/lib/python3.7/site-packages/Django-2.2.9-py3.7.egg/django/contrib/admin/static”
WSGIScriptAlias /lewhdk ‘/opt/bitnami/apps/django/django_projects/lewhdk/lewhdk/wsgi.py’

I do not know what I’m doing wrong

Hi @Majali,

Can you try running the command below to give execution permissions to the wsgi.py file?

sudo chmod +x /opt/bitnami/apps/django/django_projects/lewhdk/lewhdk/wsgi.py

Then, restart services and try to visit your website again

sudo /opt/bitnami/ctlscript.sh restart

Hi @gongomgra

Thank you for your help,

I fixed the issue, my problem was some apps were not installed properly

Thank you again for your help

Hi @Majali,

Thanks for the info. I’m glad you fixed your issue! Could you post here your solution so it can help other users in the future?

Thank you again @gongomgra

The tutorial here https://aws.amazon.com/getting-started/hands-on/deploy-python-application/ is correct

I had three issues
1- My website was running when I serve it using the command python manage.py runserver 0.0.0.0:80 but was not running using apache, the problem was some components were not installed successfully

2- I was not able to access the apache error log file using /opt/bitnami/apache2/logs/error_log I receive Permission denied. I solved it by accessing the file using SSH Filezilla

3- When running on apache, the server did not serve the static files, collectstatic did not work, I had to copy the static files manuallay

Then all worked fine

Hi,

Thanks for sharing your solution. The community will benefit from this :slight_smile: I proceed to close this ticket. Do not hesitate to open a new thread in case you find more issues.

Best regards,

Javier J. Salmerón


Was my answer helpful? Click on :heart: