Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Limit access to a django admin site through apache

I'm learning the ropes of the backend and currently trying to use an apache rule to block access to my django app's admin page, a là:

    <Directory /admin>

            Order deny,allow

            Deny from all

            Allow from xxx.xxx.xxx.xxx

    </Directory>

I also have my django/mod_wsgi alias set as

WSGIScriptAlias /app /home/django/Projects/backend/wsgi.py

I'm reading over the docs here, and here, but it's still not 100% clear how I can go about doing this, since in a django project the admin path is not specifically defined (although the static files are). My searches on this are also not turning up much, so either I'm trying to do something no one cares to do, or I'm thinking of doing it wrong (I don't want a password pop up, thank you).

The desired result here is that if you tried to access my admin page from any IP other than what I specify, then your page will just never load or timeout.

like image 792
redband Avatar asked Feb 12 '23 09:02

redband


1 Answers

Location directive is for URL paths, not the Directory directive.

<Location /admin>
        Order deny,allow
        Deny from all
        Allow from xxx.xxx.xxx.xxx
</Location>
like image 194
Graham Dumpleton Avatar answered Feb 16 '23 12:02

Graham Dumpleton