Django Token Authentication doesn't work when I access to server via domain name

I have a Django application with token authentication and I serve it via Apache2. When I do my auth required requests to the server with the domain name it returns with 401 Unauthorized HTTP error. When I do it with ip:port, it returns success. Same token is sent to the server. What might cause that? May apache server be related to this?

Here is my apache config:

<VirtualHost *:80>
        ServerAdmin ...
        ServerName semanticspace.io
        ServerAlias www.semanticspace.io
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        Alias /static /home/cuneyttyler/knowledgebase/knowledge-base-django/static
        <Directory /home/cuneyttyler/knowledgebase/knowledge-base-django/static>
                Require all granted
        </Directory>

        Alias /media /home/cuneyttyler/knowledgebase/knowledge-base-django/media
        <Directory /home/cuneyttlyer/knowledgebase/knowledge-base-django/media>
                Require all granted
        </Directory>

        <Directory /home/cuneyttyler/knowledgebase/knowledge-base-django/knowledgebase_python>
                <Files wsgi.py>
                        Require all granted
                </Files>
        </Directory>

        WSGIDaemonProcess knowledge-base-django python-path=/home/cuneyttyler/knowledgebase/knowledge-base-django python-home=/home/cuneyttyler/knowledgebase/knowledge-bas>
        WSGIProcessGroup knowledge-base-django
        WSGIScriptAlias / /home/cuneyttyler/knowledgebase/knowledge-base-django/knowledgebase_python/wsgi.py
</VirtualHost>

>Solution :

Apache does not pass on the Authorization header by default, you need to add the following to your VirtualHost config and restart Apache

WSGIPassAuthorization On

Leave a Reply