Error 403 Forbidden --Deploying Django project

Keywords: Django - AWS - Technical issue - Permissions
bnsupport ID: 0b4f4c04-156e-8fad-ff16-987f9d03084f
Description:
hi!
I’m trying to deploy a Django projects on AWS Lightsail.
After uploading the data and conf apache2 ( vhost-file-conf) , now I visualize a nice "403 error "
why?

here my "macelleria-https-vhost.conf :

<IfDefine !IS_macelleria_LOADED>
Define IS_macelleria_LOADED
WSGIDaemonProcess macelleria python-home=/opt/bitnami/python  python-path=/opt/bitnami/apache/htdocs/projects/macelleria_env/lib/python3.8 processes=2 threads=15
</IfDefine>
<VirtualHost *:443 _default_:443>
ServerAlias *
SSLEngine on
SSLCertificateFile “/path/to/certificate”
SSLCertificateKeyFile "/path/to/SSL” (yes .. I updated this :) 
WSGIProcessGroup macelleria
Alias /robots.txt /opt/bitnami/projects/macelleria/static/robots.txt
Alias /favicon.ico /opt/bitnami/projects/macelleria/static/favicon.ico
Alias /static/ /opt/bitnami/projects/macelleria/static/
<Directory /opt/bitnami/projects/macelleria/static>
Require all granted
</Directory>
Alias /media/ /opt/bitnami/projects/media/
<Directory /opt/bitnami/projects/media>
Require all granted
</Directory>
WSGIScriptAlias / /opt/bitnami/projects/macelleria/macelleria_progetto/wsgi.py
<Directory /opt/bitnami/projects/macelleria/macelleria_progetto>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>

… and here “ls -la” output in /opt/bitnami/projects/macelleria_sito :

total 1136
drwxr-xr-x 9 bitnami daemon   4096 Apr  4 19:53 .
drwxr-xr-x 4 bitnami root     4096 Apr  8 15:30 ..
drwxr-xr-x 4 bitnami daemon   4096 Apr  4 19:51 cart_app
drwxr-xr-x 5 bitnami daemon   4096 Apr  4 19:52 checkout
-rw-r--r-- 1 bitnami daemon 299008 Apr  4 19:51 db.sqlite3
-rw-r--r-- 1 bitnami daemon   6148 Apr  4 19:51 .DS_Store
-rw-r--r-- 1 bitnami daemon 812675 Apr  4 19:51 IMG_2452.jpg
drwxr-xr-x 5 bitnami daemon   4096 Apr  4 19:52 macelleria_app
drwxr-xr-x 3 bitnami daemon   4096 Apr  4 19:52 macelleria_progetto
drwxr-xr-x 4 bitnami daemon   4096 Apr  4 19:52 manage_data
-rw-r--r-- 1 bitnami daemon    675 Apr  4 19:51 manage.py
drwxr-xr-x 9 bitnami daemon   4096 Apr  4 19:53 static
drwxr-xr-x 3 bitnami daemon   4096 Apr  4 19:53 templates

and in /opt/bitnami/projects:

total 16
drwxr-xr-x  4 bitnami root    4096 Apr  8 15:30 .
drwxr-xr-x 18 root    root    4096 Apr  4 13:28 ..
drwxr-xr-x  9 bitnami daemon  4096 Apr  4 19:53 macelleria_sito
drwxr-xr-x  2 bitnami bitnami 4096 Apr  4 20:04 media

Can someone help me ?

Hi @bevilacqua01,

Just to confirm, did you follow our guides when deploying your Django application?

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

Please ensure you follow all the necessary steps to deploy and configure your application.

Happy to help!


Was my answer helpful? Click on :heart:

1 Like

Yes, I followed all but doesn’t work

here the ‘Bitnami.conf’

# Default Virtual Host configuration.

# Let Apache know we're behind a SSL reverse proxy
SetEnvIf X-Forwarded-Proto https HTTPS=on

<VirtualHost _default_:80>
DocumentRoot "/opt/bitnami/apache/htdocs"
<Directory "/opt/bitnami/apache/htdocs">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

  # Error Documents
ErrorDocument 503 /503.html
</VirtualHost>

Include "/opt/bitnami/apache/conf/bitnami/bitnami-ssl.conf"

I haven’t touched the file as the guide says but this file is correct ? my projects is in /opt/bitnami/projects/macelleria (as the guide assume )

update— here the error-log:

Fri Apr 09 21:03:22.331763 2021] [wsgi:error] [pid 3650] [remote 79.52.250.157:62967] mod_wsgi (pid=3650): Failed to exec Python script file '/opt/bitnami/projects/macelleria_progetto/macelleria_progetto/wsgi.py'.
[Fri Apr 09 21:03:22.331833 2021] [wsgi:error] [pid 3650] [remote 79.52.250.157:62967] mod_wsgi (pid=3650): Exception occurred processing WSGI script '/opt/bitnami/projects/macelleria_progetto/macelleria_progetto/wsgi.py'.
[Fri Apr 09 21:03:22.331991 2021] [wsgi:error] [pid 3650] [remote 79.52.250.157:62967] Traceback (most recent call last):
[Fri Apr 09 21:03:22.332065 2021] [wsgi:error] [pid 3650] [remote 79.52.250.157:62967]   File "/opt/bitnami/projects/macelleria_progetto/macelleria_progetto/wsgi.py", line 16, in <module>
[Fri Apr 09 21:03:22.332074 2021] [wsgi:error] [pid 3650] [remote 79.52.250.157:62967]     application = get_wsgi_application()
[Fri Apr 09 21:03:22.332085 2021] [wsgi:error] [pid 3650] [remote 79.52.250.157:62967]   File "/opt/bitnami/python/lib/python3.8/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
[Fri Apr 09 21:03:22.332090 2021] [wsgi:error] [pid 3650] [remote 79.52.250.157:62967]     django.setup(set_prefix=False)
[Fri Apr 09 21:03:22.332100 2021] [wsgi:error] [pid 3650] [remote 79.52.250.157:62967]   File "/opt/bitnami/python/lib/python3.8/site-packages/django/__init__.py", line 19, in setup
[Fri Apr 09 21:03:22.332105 2021] [wsgi:error] [pid 3650] [remote 79.52.250.157:62967]     configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Fri Apr 09 21:03:22.332114 2021] [wsgi:error] [pid 3650] [remote 79.52.250.157:62967]   File "/opt/bitnami/python/lib/python3.8/site-packages/django/conf/__init__.py", line 82, in __getattr__
[Fri Apr 09 21:03:22.332120 2021] [wsgi:error] [pid 3650] [remote 79.52.250.157:62967]     self._setup(name)
[Fri Apr 09 21:03:22.332129 2021] [wsgi:error] [pid 3650] [remote 79.52.250.157:62967]   File "/opt/bitnami/python/lib/python3.8/site-packages/django/conf/__init__.py", line 69, in _setup
[Fri Apr 09 21:03:22.332135 2021] [wsgi:error] [pid 3650] [remote 79.52.250.157:62967]     self._wrapped = Settings(settings_module)
[Fri Apr 09 21:03:22.332143 2021] [wsgi:error] [pid 3650] [remote 79.52.250.157:62967]   File "/opt/bitnami/python/lib/python3.8/site-packages/django/conf/__init__.py", line 170, in __init__
[Fri Apr 09 21:03:22.332149 2021] [wsgi:error] [pid 3650] [remote 79.52.250.157:62967]     mod = importlib.import_module(self.SETTINGS_MODULE)
[Fri Apr 09 21:03:22.332157 2021] [wsgi:error] [pid 3650] [remote 79.52.250.157:62967]   File "/opt/bitnami/python/lib/python3.8/importlib/__init__.py", line 127, in import_module
[Fri Apr 09 21:03:22.332163 2021] [wsgi:error] [pid 3650] [remote 79.52.250.157:62967]     return _bootstrap._gcd_import(name[level:], package, level)
[Fri Apr 09 21:03:22.332172 2021] [wsgi:error] [pid 3650] [remote 79.52.250.157:62967]   File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
[Fri Apr 09 21:03:22.332181 2021] [wsgi:error] [pid 3650] [remote 79.52.250.157:62967]   File "<frozen importlib._bootstrap>", line 991, in _find_and_load
[Fri Apr 09 21:03:22.332191 2021] [wsgi:error] [pid 3650] [remote 79.52.250.157:62967]   File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
[Fri Apr 09 21:03:22.332200 2021] [wsgi:error] [pid 3650] [remote 79.52.250.157:62967]   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
[Fri Apr 09 21:03:22.332210 2021] [wsgi:error] [pid 3650] [remote 79.52.250.157:62967]   File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
[Fri Apr 09 21:03:22.332219 2021] [wsgi:error] [pid 3650] [remote 79.52.250.157:62967]   File "<frozen importlib._bootstrap>", line 991, in _find_and_load
[Fri Apr 09 21:03:22.332228 2021] [wsgi:error] [pid 3650] [remote 79.52.250.157:62967]   File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
[Fri Apr 09 21:03:22.332249 2021] [wsgi:error] [pid 3650] [remote 79.52.250.157:62967] ModuleNotFoundError: No module named 'macelleria_progetto'

Hi @bevilacqua01,

The error is clear in the error_log file of Apache

[Fri Apr 09 21:03:22.332249 2021] [wsgi:error] [pid 3650] [remote 79.52.250.157:62967] ModuleNotFoundError: No module named 'macelleria_progetto'

It seems that your project is missing some libraries/information and that’s why Apache can’t deploy it. Please review your project’s code to ensure it works properly before deploying it on top of Apache.

Note: you can also deploy a sample Django project to ensure the Apache’s configuration work as expected before deploying your custom project.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.