Search code examples
djangoapacheamazon-ec2wsgihttp-status-code-403

403 not found in EC2 - apache&WSGI error


I have editted the httpd.conf inside apache by adding:

<Directory /home/ec2-user/hqlocal>
Order deny,allow
Allow from all
</Directory>

WSGIScriptAlias / /home/ec2-user/hqlocal/hq_local/apache/django.wsgi
WSGIPythonPath /usr/lib/python2.7/site-packages

# Serving Django admin static files
Alias /static/admin /usr/lib/python2.7/site-packages/django/contrib/admin/static/admin
# Serving Django static files (our own files use in our app), assuming in settings.py,     STATIC_ROOT is “/var/www/static/” and our STATIC_URL is “/static/”   
Alias /static /var/www/static/

I have tried many solutions that fix the 403 problem like swapping deny and allow, and so on. But none of them works, I still get 403 cannot access '/'

Therefore, I tried commenting line by line.

The result is that the line

WSGIScriptAlias / /home/ec2-user/hqlocal/hq_local/apache/django.wsgi

causing the problem.

By adding this line, the system becomes 403 but without it, when entering the public DNS, the server will point to Apache default page.

So, I assume that Apache may not have permission to read this file. Therefore, i changed the permission to be global. However, it still didn't work properly.

May I know how to fix this?

Thank you very much.


Solution

  • The directory '/home/ec2-user' is likely not readable to the Apache user. Watch:

    for common mod_wsgi setup issues including this one.

    Also, you should not need:

    WSGIPythonPath /usr/lib/python2.7/site-packages
    

    if mod_wsgi is actually compiled against the system Python 2.7. If it isn't compiled against the system Python 2.7, but another version, you should not be forcing it to use modules installed into another Python version as that will cause problems. You should reinstall mod_wsgi with version compiled against correct Python version you want to use.