0

I want to deploy my Django project on my apache server but even if I follow django's example in deploying with apache I get a 403 Error. I am using:

  1. django 1.6
  2. apache 2.4.7
  3. python 2.6.x

My wsgi.py is the one created by django-admin startproject

import os, sys

#root = os.path.join(os.path.dirname(__file__),'..')
# sys.path.insert(0, root)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "rhombus.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

My VirutalServer conf file is the following

rhombus.conf

WSGIPythonPath /var/www/rhombus2

<VirtualHost *:80>
    ServerAdmin webmast@rhombus.com
    ServerName myrhombus.com
    ServerAlias www.myrhombus.com
    DocumentRoot /var/www/rhombus2
    WSGIScriptAlias / /var/www/rhombus2/rhombus/wsgi.py
    <Directory /var/www/rhombus2/rhombus>
        <Files wsgi.py>
            Require all granted
        </Files>
        Options Indexes FollowSymLinks
        Require all granted
    </Directory>
</VirtualHost>

and I have placed rhombus2 inside /var/www. All foldters and files are at 755 with sudo chmod -R 755 /var/www/rhombus2. But even with that I get a Forbidden Error.

Among other things, when I remove the WSGIPythonPath, I don't get Import Error, which I probably should. I know it is not the secure way to have everything (code too) under document root. But I really need to have it working first, and then make it secure. Is there something wrong with my code?

EDIT: error.log

(13)Permission denied: [client 127.0.0.1:46669] AH00035: access to /favicon.ico denied (filesystem path '/home/avlahop/development/django') because search permissions are missing on a component of the path

Not sure why it's showing me this path, cause there isn't it anywhere in my rhombus.conf.

EDIT2: I also don't have any other site enabled. My hosts file has the following line

127.0.0.1    www.myrhombus.com
Apostolos
  • 7,763
  • 17
  • 80
  • 150

2 Answers2

0

here is my working virtualhost

Listen 9090
<VirtualHost *:9090>
    ServerName www.test.com
    WSGIDaemonProcess   project processes=2 threads=15 display-name=%{GROUP}
    WSGIProcessGroup project
    WSGIScriptAlias / /srv/www/project/project/wsgi.py
    Alias /static /srv/www/project/static/
    Alias /favicon.ico /srv/www/project/static/favicon.ico

    ErrorLog /var/log/apache2/project_error.log
    LogLevel Info
    CustomLog /var/log/apache2/project_access.log combined
</VirtualHost>

and wsgi.py

import os, sys, site

from os.path import dirname, abspath, join
site.addsitedir('/home/user/virtualenvy/some_project/lib/python2.7/site-packages')

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "some_project.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

I hope it helps You :)

qwetty
  • 1,238
  • 2
  • 10
  • 24
  • thx @qwetty. Though i am not under virtualenv...Where does apache 2 gets the problematic path? Which is 755 in permissions too – Apostolos May 19 '14 at 08:57
  • Do You try to add `Alias /favicon.ico` in virtualhost configuration? Almost any browser automatically requests for this file. – qwetty May 19 '14 at 09:17
  • No, I didn't but why is it seeking for it in wrong path. Different from my VirtualHost conf Added Alias /media/ /var/www/rhombus2/media/ Alias /static/ /var/www/rhombus2/static/ Alias /favicon.ico /var/www/rhombus2/static/favicon.ico Not working – Apostolos May 19 '14 at 09:39
  • From other side. Where apache should take information about path, while You didn't specify ... ? – qwetty May 19 '14 at 09:49
  • I didn't get what you are trying to tell me. Where apache should do what? – Apostolos May 19 '14 at 09:51
  • I didn't see your previous comment. If You add Alias for favicon and it steel doesn't work, unfortunately I can't help You :( – qwetty May 19 '14 at 10:37
0

Assume that Appache's username is www-data, run this command to check www-data's permission on your application folder: sudo su - www-data -s /bin/bash -c 'ls /var/www/rhombus2/rhombus/'

Since you did chmod 755 the folder, so I think it'll work, if not, check permisson of /var and /var/www

Also, paste content of wsgi.py might be helpful for solving problem.

heroandtn3
  • 164
  • 1
  • 7
  • wsgi.py code is at my initial post You can check it out. Thanks for answering – Apostolos May 19 '14 at 09:38
  • But where's the rest of that wsgi file? That's not the whole code that's created by Django. You need the bit that actually creates the WSGI application object. – Daniel Roseman May 19 '14 at 09:40
  • You are right...added it too Also your command listed the files inside /var/www/rhombus2/rhombus, so it probably works – Apostolos May 19 '14 at 09:44
  • @Apostolos: did you solve your problem? I think this [link](http://stackoverflow.com/questions/4807176/apache-mod-wsgi-error-forbidden-you-dont-have-permission-to-access-on-this-s?rq=1) might be useful – heroandtn3 May 22 '14 at 03:31
  • I did it back from the beginning and put everything inside /srv/www/{mysitename}} and worked :) – Apostolos May 22 '14 at 13:37