Django | Error 403 "Forbidden You don't have permission to access this resource"

Keywords: Django - AWS - Technical issue - Permissions
bnsupport ID: 98c5e367-aacb-99ac-d699-f068877a75ed
Description:
Hi bitnami team,

Before creating this ticket, I've tried many solutions on this forums and stackoverflow and I still have this restriction.

I have created a Django app hosted by AWS lightsail. I've followed this tutorial : "https://docs.bitnami.com/aws/infrastructure/django/get-started/get-started/" for the launch. Everything works when I use the django server on : http://SERVER-IP:3030.

I've followed the step 2. Serve Your Application Through The Apache Web Server and choosed the: Approach B: Self-Contained Bitnami Installations.

But I have a 403( Forbidden You don't have permission to access this resource.) error when I go to http://SERVER-IP.

My app is stored : /opt/bitnami/apps/Django-API-Website

This is my app tree:

Django-API-Website/
     backend/
          settings/
               __init__.py 
               base.py
               dev.py
               prod.py 
               stag.py
          wsgi/
               dev.py
               prod.py
               stag.py
          __init__.py
          asgi.py
          urls.py
     conf/
          httpd-app.conf
          httpd-prefix.conf
     ...
     ...
     manage.py
     secrets.json

In my backend/settings/stag.py

'''Use this for staging'''

from .base import *

DEBUG = False
ALLOWED_HOSTS = ['SERVER-IP']
WSGI_APPLICATION = 'backend.wsgi.stag.application'

DATABASES = {
    'default': {
        'ENGINE': get_secret('ENGINE'),
        'NAME': get_secret('NAME_STAG'),
        'USER': get_secret('USER_STAG'),
        'PASSWORD': get_secret('PASSWORD_STAG'),
        'HOST': get_secret('HOST_STAG'),
        'PORT': get_secret('PORT'),
    }
}

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]

In my backend/wsgi/stag.py

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings.stag')

application = get_wsgi_application()

In my conf/httpd-app.conf

<IfDefine !IS_DJANGOSTACK_LOADED>
    Define IS_DJANGOSTACK_LOADED
    WSGIDaemonProcess wsgi-djangostack   processes=2 threads=15    display-name=%{GROUP}
</IfDefine>

<Directory "/opt/bitnami/apps/Django-API-Website/backend">
    Options +MultiViews
    AllowOverride All

    <IfVersion >= 2.3>
        Require all granted
    </IfVersion>

    WSGIProcessGroup wsgi-djangostack
    WSGIApplicationGroup %{GLOBAL}
</Directory>

Alias /Django-API-Website/static "/opt/bitnami/apps/django/lib/python3.8/site-packages/Django-3.0.8-py3.8.egg/django/contrib/admin/static"

WSGIScriptAlias /Django-API-Website '/opt/bitnami/apps/Django-API-Website/backend/wsgi/stag.py'

# https://docs.bitnami.com/aws/faq/administration/control-services/

In my conf/httpd-prefix.conf

Include "/opt/bitnami/apps/Django-API-Website/conf/httpd-app.conf"

In my **/opt/bitnami/apache2/logs/error_log **

AH01630: client denied by server configuration: /opt/bitnami/projects, referer: http://SERVER-IP/

I also run the bitnami support tool : 98c5e367-aacb-99ac-d699-f068877a75ed

Thank's for your time

Regards

Hi @jonathan.pagani,

I think this path is wrong, you should be pointing to the static files inside your project

Alias /Django-API-Website/static "/opt/bitnami/apps/Django-API-Website/static"

and restart Apache later.

Hi @jota,

Thank's for your reply.

Yes my path was wrong, but after change, I still have the 403 error.

In the documentation part B, they said (think there is typo for apache22 instead of apache2 :slight_smile: ):
https://docs.bitnami.com/aws/infrastructure/django/get-started/deploy-django-project/

but in there is no httpd-prefix.conf to add this line. Do I have to create this file ? This file may cause the 403 error?

Regards

Hi @jonathan.pagani,

This user had a similar issue, can you take a look at the information in his thread?

https://community.bitnami.com/t/trying-to-get-app-working-and-getting-client-denied-by-server-configuration-error/85050

Yes, there is a typo, it's apache2. But you are using the latest available version so you must follow the Approach A instructions.

Hi @jota,

I tried the approach A and everything works.

You can close the case.

Thanks

1 Like

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

Thanks for the feedback, we have fixed the typo in https://docs.bitnami.com/aws/infrastructure/django/get-started/deploy-django-project/