Apache mod_wsgi error: Forbidden You don't have permission to access / on this server
Solution 1
The second directory block doesn't match where you have your WSGI script file installed. It is very bad practice though to stick the WSGI script file in a location where source code or other sensitive files exist, ie., same directory or sub directory. Instead you should stick it in a sub directory of its own. Thus:
WSGIScriptAlias / /home/wong2/Code/python/django2/atest/apache/setting.wsgi
<Directory "/home/wong2/Code/python/django2/atest/apache">
Order allow,deny
Allow from all
</Directory>
So, create 'apache' subdirectory under 'atest'. Move 'setting.wsgi' into that 'apache' subdirectory and change config to above.
Your problem also may be caused by restrictive permisions on your home directory as Apache cannot see inside.
Go watch:
http://code.google.com/p/modwsgi/wiki/WhereToGetHelp?tm=6#Conference_Presentations
as it explains these permissions problems as well as issues like where to stick your code and the WSGI script file.
Also read:
http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango
Solution 2
With Django 1.5+ you should use the suggested way described in the documentation:
WSGIScriptAlias / /path/to/mysite.com/mysite/wsgi.py
WSGIPythonPath /path/to/mysite.com
<Directory /path/to/mysite.com/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/modwsgi/
Solution 3
I had the same problem due to restricted file permissions.
By default your home folder user has the settings:
ls -l /home/
drwx------ 36 user user 12288 Nov 28 20:56 user
meaning that no one else but yourself is able to even browse that folder.
Adding execute option to the folder fixed my problem
chmod o+x /home/user/
ls -l /home/
drwx-----x 36 user user 12288 Nov 28 20:56 user
Comments
-
wong2 over 3 years
I'm using Ubuntu 10.04.
I create a django project under/home/wong2/Code/python/django2/
namedatest
and create a wsgi filesetting.wsgi
in the same directory
Here is the content ofsetting.wsgi
:import os import sys path = '/home/wong2/Code/python/django2' if path not in sys.path: sys.path.append(path) os.environ["DJANGO_SETTINGS_MODULE"] = "atest.settings" from django.core.handlers.wsgi import WSGIHandler application = WSGIHandler()
and here is what I add to my my httpd.conf:
<VirtualHost *:80> ServerName localhost WSGIScriptAlias / /home/wong2/Code/python/django2/setting.wsgi <Directory /> Options FollowSymLinks AllowOverride None Order deny,allow Allow from all </Directory> <Directory "/home/wong2/Code/python/django2/atest"> Order allow,deny Allow from all </Directory> </VirtualHost>
The problem is, when I visit http://localhost, it says
Forbidden
You don't have permission to access / on this server.
Thanks a lot.
-
wong2 over 13 yearsWhen I visit localhost/index.html, it still show the
403 Forbidden
error -
Plahcinski over 13 yearsOn second thought, Your issue might just be a permissions issue. If www-data (linux apache user) can't read your home directory that might throw that error.
-
Drewness almost 9 yearsFYI -
Require all granted
will only work on Apache 2.4.x and based on the OP'shttpd.conf
it seems he is using 2.2.x or at least the syntax as such. That said, good answer! -
ThePhi almost 4 yearsnew link for Django 3: docs.djangoproject.com/en/3.0/howto/deployment/wsgi/modwsgi