4

Alright, so i am following this tutorial. When i try to access my site through my local server i get this peculiar error:

Forbidden You don't have permission to access / on this server. Apache/2.4.6 (Ubuntu) Server at mysite.com Port 80.

Αs far as i am concerned i have done everything right (i implemented twice the proposed method) and this could easily be an OS error (i am running Mint 16 and error says (Ubuntu)), however i am not experienced and therefore i need some help.

I did some research but none of these (1,2) questions along with others, does not seem to answer my case.

So here is mysite.conf file:

<VirtualHost *:80>
WSGIScriptAlias / /home/nick/Mysite/mysite.wsgi

ServerName mysite.com
Alias /static /var/www/mysite/static/

<Directory /var/www/mysite/>

Options All
AllowOverride All
Require all granted

</Directory>
</VirtualHost>

and my hosts file which shows how the ip address is redirected to my local host:

127.0.0.1   localhost
127.0.1.1   nick-HP-Notebook-PC
192.168.1.2 mysite.com
192.168.1.2 mysite2.com

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

So what do you suggest the problem is. Could this be simply a Linux related error? and please let me know if you need additional info about the project or anything.

Thanks a ton.

Update:

Here is my .wsgi file:

import os
import sys
sys.path = ['/var/www/mysite'] + sys.path
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

I also get this message when i restart the server.

Restarting web server apache2                                                AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message         [ OK ]

Maybe this helps?

Community
  • 1
  • 1

3 Answers3

1

If this is exactly your config file then i doubt the path that you're using is wrong. Please fix that first.

Set WSGIScriptAlias this to correct path.

Then your WSGI file must look something like:

import os
import sys

os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
Aidas Bendoraitis
  • 3,965
  • 1
  • 30
  • 45
Anup
  • 743
  • 6
  • 12
  • i have updated my question so it reflects your answer. wsgi file is good so is the path to the project –  Jan 27 '14 at 14:23
  • 1
    Are you sure that the path you have put up in wsgi is correct ? and also post the error – Anup Jan 27 '14 at 14:27
  • are you referring to the `WSGIScriptAlias / /home/nick/Mysite/mysite.wsgi` path? Yes i am quite certain this is the correct path. Which error?? –  Jan 27 '14 at 14:37
  • 1
    sys.path = ['/var/www/mysite'] + sys.path this was the path i was referring to not the WSGIScriptAlias – Anup Jan 27 '14 at 14:52
  • Oh ok sorry. My projects structure is as follows: `/var/www/mysite/mysite/wsgi.py` file. How should it be? –  Jan 27 '14 at 15:09
  • So in your /var/www/mysite/mysite/wsgi.py file os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings' and WSGIScriptAlias / /var/www/mysite/mysite/wsgi – Anup Jan 27 '14 at 15:19
  • can you be a bit more precise please? inside the `mysite.conf` file, what is the purpose of changing path from `WSGIScriptAlias / /home/nick/Mysite/mysite.wsgi` to `WSGIScriptAlias / /var/www/mysite/mysite/wsgi`? If you can't provide a solid answer please stop trying to help me, its rather confusing. appreciate all the help –  Jan 27 '14 at 15:36
1

A things to start with:

WSGIScriptAlias / /home/nick/Mysite/mysite.wsgi

For this, you do not have a corresponding:

<Directory/home/nick/Mysite>
<Files mysite.wsgi>
Require all granted
</Files>
</Directory>

Also, a home directory such as /home/nick is usually not readable to other users and so Apache wouldn't be able to read stuff in that directory anyway.

Next is:

Alias /static /var/www/mysite/static/

You shouldn't have a trailing slash on final path. Not having them matched when for a sub URL can cause issues, although usually when the trailing slash is on the URL and missing for the file system path. Better just to have them match as far as whether a trailing slash is used or not.

Graham Dumpleton
  • 57,726
  • 6
  • 119
  • 134
  • So the project files should be moved to another dir? And it best if i comment the `Alias /static /var/www/mysite/static/` ? –  Jan 28 '14 at 10:22
  • 1
    Having it in your home directory is not ideal. You will still need the Alias directive so Apache can host static files for Django, you just need to set it correctly. See https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/modwsgi/#serving-files – Graham Dumpleton Jan 29 '14 at 02:44
1

I had the same problem.

your .wsgi script should be located in the /var/www/mysite/ folder and then your config files should be adjusted as necessary.

Also delete the leading / in :

.. Alias /static /var/www/mysite/static ..

steve
  • 41
  • 1