Trouble with Apache, mod_wsgi, and Django configuration - django

Just set up a 64 bit ubuntu EC2 instance using the Bitnami DjangoStack image.
So far I have installed a few python dependencies and removed the Project django app which was created by default. I created a new app with 'django-admin.py startproject projectname'. I then followed the instructions here: http://wiki.bitnami.org/Components/Django, attempting to setup apache.
Here is my projectname.conf file:
Alias /static "/opt/bitnami/apps/django/lib/python2.7/site-packages/django/contrib/admin/static"
<Directory '/opt/bitnami/apps/django/lib/python2.7/site-packages/django/contrib/'>
Order allow,deny
Allow from all
</Directory>
WSGIScriptAlias /URL_mount_point "/opt/bitnami/apps/django/scripts/projectname.wsgi"
<Directory '/opt/bitnami/apps/django/scripts'>
Order allow,deny
Allow from all
</Directory>
Here is my projectname.wsgi
import os, sys
sys.path.append('/opt/bitnami/apps/django/django_projects')
sys.path.append('/opt/bitnami/apps/django/django_projects/projectname')
os.environ['DJANGO_SETTINGS_MODULE'] = 'projectname.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
Here are the last three lines of my httpd.conf:
Include "/opt/bitnami/apache2/conf/ssi.conf"
Include "/opt/bitnami/apache2/conf/bitnami/httpd.conf"
Include "/opt/bitnami/apps/django/conf/projectname.conf"
After doing this and restarting apache, hitting mydomain.com/projectname still comes up with a 404 (the Bitnami landing page comes up just fine at mydomain.com).
Am I missing something here? Are my paths in projectname.wsgi incorrect (I have not strayed from the default Bitnami directory structure). Or is there some additional step I am missing here?

You should be accessing:
http://mydomain.com/URL_mount_point
Since it appears you have not shown your original configuration, hard to say whether that is the issue or whether is a typo of sorts.

I added this to my httpd.conf
WSGIScriptAlias / /opt/bitnami/apps/django/scripts/projectname.wsgi
<Directory '/opt/bitnami/apps/django/django_projects/projectname'>
Order allow,deny
Allow from all
</Directory>
and that seemed to fix it.

Related

how to resolve You don't have permission to access / on this server

Hi I need help in integrating django with apache and mod_wsgi on centos6.
I am getting following error every time---"Forbidden You don't have permission to access / on this server."
My django project path= /home/mchauras/esapp/eswebsite
my apache version is 2.2.15
my .conf file looks like this----
<VirtualHost *:80>
DocumentRoot /home/mchauras/esapp/eswebsite/
Alias /static /home/mchauras/esapp/eswebsite/esapp/static
<Directory /home/mchauras/esapp/eswebsite/esapp/static>
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride None
Order deny,allow
Allow from all
</Directory>
<Directory /home/mchauras/esapp/eswebsite/eswebsite>
<Files wsgi.py>
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride None
Order deny,allow
Allow from all
</Files>
</Directory>
WSGIDaemonProcess esapp python-path=/home/user/myproject:/home/mchauras/esapp/eswebsite/myvenv/lib/python3.5/site-packages/
WSGIProcessGroup esapp
WSGIScriptAlias / /home/mchauras/esapp/eswebsite/eswebsite/wsgi.py
ErrorLog /home/mchauras/esapp/eswebsite/error.log
CustomLog /home/mchauras/esapp/eswebsite/access.log combined
</VirtualHost>
my wsgi.py file is like this---
import os
import sys
from django.core.wsgi import get_wsgi_application
sys.path.append('/home/mchauras/esapp/eswebsite')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "eswebsite.settings")
application = get_wsgi_application()
its looks like you did not login as a administrator user or maybe you need to changes and enable all file permission in the path
This specific error is usually always caused by the user that Apache runs as not being able to access the WSGI script file. It is not enough to just make the file itself readable to others. All the directories from '/' down to that directory must also be accessible to the user Apache runs as. As home directories for users are not usually readable by others, the Apache user cannot see into it. You are better off moving the application directory outside of your home directory.
Another possible cause, although one which usually results in a slightly different error, is having SELinux enabled where the profile for Apache httpd server on SELinux doesn't allow access to the directories where your application is.

Error trying to configure apache and django

I'm trying to install a django 1.3 app on apache 2.2 with mod_wsgi on windows 7. I added the following lines to httpd.conf
Listen 8080
...
LoadModule wsgi_module modules/mod_wsgi.so
Alias /static/ "C:/Users/.../my_app/my_app/static/"
<Directory "C:/Users/.../my_app/my_app/static">
Order deny,allow
Allow from all
<Directory>
WSGIScriptAlias / "C:/Users/.../my_app/my_app/wsgi.py"
WSGIPythonPath "C:/Users/.../my_app/"
<Directory "C:/Users/.../my_app/my_app">
<Files wsgi.py>
Order allow,deny
Allow from all
<Files>
<Directory>
wsgi.py
import os
import sys
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'my_app.settings')
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandlers()
path = 'C:/Users/.../my_app/my_app'
if path not in sys.path:
sys.path.append(path)
The wsgi.py file is in the same folder as settings.py and urls.py
When I go to localhost:8080 it says:
Not found The requested URL / was not found on this server
Note: I'm totally new to apache, I don't know what i'm missing, some docs show a way to configure it and others show a completly diferent way to do the same thing.
Any ideas of what's wrong with this configuration.
Since you are using Windows 7, my first guess is permissions. Anything past the "Users" folder is going to have weird permissions issues. When I develop anything on Windows locally, I always place the project in a root folder, like "C:/projects/django/my_project/". Also, make sure you look at the Windows Firewall settings (if anything, for debug, disable Windows Firewall for a mo, or better yet add a Firewall rule):
http://www.howtogeek.com/112564/how-to-create-advanced-firewall-rules-in-the-windows-firewall/
Honestly, half of my trouble with windows is making sure project and development settings are outside of core structures. Don't install services to "C:/Program Files" or make projects folder in "C:/Users".

How to setup Django, mod_wsgi and apache on Mac OSX Lion?

I am having trouble setting Django with Apache on Mac OSX Lion (10.7.2). I created a Django project as per the tutorial and can run it on the development server. Now I want to run it locally on my Mac with Apache. I created the two files indicated below.
apache_django_wsgi.conf
WSGIDaemonProcess django
WSGIProcessGroup django
Alias /site_media/ "/Users/David/Dropbox/sites/walble/media/"
<Directory "/Users/David/Dropbox/sites/walble/media">
Order allow,deny
Options Indexes
Allow from all
IndexOptions FancyIndexing
</Directory>
Alias /media/ "/Library/Python/2.7/site-packages/django/contrib/admin/media/"
<Directory "/Library/Python/2.7/site-packages/django/contrib/admin/media">
Order allow,deny
Options Indexes
Allow from all
IndexOptions FancyIndexing
</Directory>
WSGIScriptAlias /walble "/Users/David/Dropbox/sites/walble/apache/walble.wsgi"
<Directory "/Users/David/Dropbox/sites/walble/apache">
Allow from all
</Directory>
walble.wsgi
import os
import sys
sys.path.append('/Users/David/Dropbox/sites/walble')
sys.path.append('/Users/David/Dropbox/sites')
os.environ['DJANGO_SETTINGS_MODULE'] = 'walble.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
In httpd.conf, I enabled
LoadModule wsgi_module libexec/apache2/mod_wsgi.so and then added the following line.
Include /Users/David/Dropbox/sites/walble/apache/apache_django_wsgi.conf
I restarted Apache and then in the browser I typed in http://localhost/walble but I get a forbidden message like so
Forbidden
You don't have permission to access /walble on this server.
Apache/2.2.20 (Unix) DAV/2 mod_wsgi/3.3 Python/2.7.1 PHP/5.3.6 with Suhosin-Patch Server at localhost Port 80
Any suggestions on what I might be doing wrong?
This is a common permissions problem. The Apache user does not have execute permissions on the walble.wsgi file.

I need help on configuring mod_wsgi and Django

Apache & mod_wsgi are configured correctly (I've created a hello
world .html apache file and a hello world mod_wsgi application with
no problems). I now need my Django app to work with my django.wsgi
file. What makes me think that it's not recognizing my wsgi file is that I
went into my django.wsgi file I created and completely deleted all of
the code in the file and restarted Apache and it still gives me the
same page (a listing of the files from Django app, not my actual
Django application. Configuring Apache and mod_wsgi went really well
but I'm at a loss of how to fix this. Here are some details:
Here is my current django.wsgi file:
import os
import sys
sys.path.append('/srv/www/duckling.org/store/')
os.environ['DJANGO_SETTINGS_MODULE'] = 'store.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
I've tried a few different versions of the django.wsgi file
(including a version like the one over at http://www.djangoproject.com/).
This version of my wsgi is from here:
http://library.linode.com/frameworks/django-apache-mod-wsgi/ubuntu-10...
Also, here is my vhost apache configuration file below. I think these
are the main files that are suppose to do the job for me. Let me know if
you see any errors in what I'm doing and what else I might do to fix
this. The django app runs fine on the django's built-in development
server so I'm thinking it might have something with my paths.
No errors in my apache error.log file as well. It's acting as there's
no problem at all, which is not the case...the project isn't loading,
like I said just a listing of my files and directories of my Django
project. Here is my apache config file:
<VirtualHost 1.2.3.4:80>
ServerAdmin hi#duckling.org
ServerName duckling.org
ServerAlias www.duckling.org
DocumentRoot /srv/www/duckling.org/store/
<Directory /srv/www/duckling.org/store/>
Order Allow,Deny
Allow from all
</Directory>
Alias /static/ /srv/www/duckling.org/store/static/
<Directory /srv/www/duckling.org/store/static>
Order deny,allow
Allow from all
</Directory>
WSGIScriptAlias store/ /srv/www/duckling.org/store/wsgi-scripts/django.wsgi
<Directory /srv/www/wsgi-scripts>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
And here are versions of the stack that I'm using, I saw over at the
mod_wsgi site that you all would like the versions of what I'm using
on the server:
Apache/2.2.14 (Ubuntu) PHP/5.3.2-1ubuntu4.5 with Suhosin-Patch
mod_python/3.3.1 Python/2.6.5 mod_wsgi/2.8
thanks,
j.
For a start, you should definitely not keep your Django files under your DocumentRoot. There's no need for them to be there, and it's a potential security risk - as you've seen, your current misconfiguration allows Apache to serve up your files directly: an attacker could guess that and download your settings.py, complete with your database password.
So, get rid of that DocumentRoot directive completely, as well as the first Directory section which allows direct access to /srv/www/duckling.org/store/. (You probably don't need the one serving up /srv/www/wsgi-scripts either.) That should make things a bit better.
By the way, this configuration will serve your website under duckling.org/store - is that what you want? If you want it under the root, you should just use:
WSGIScriptAlias / /srv/www/duckling.org/store/wsgi-scripts/django.wsgi

Django website on Apache with wsgi failing

I have a website I've built in django that I'm trying to get working on our corporate Apache server (on debian) for our intranet at my workplace. Unfortunately, Apache keeps returning server errors whenever I try to navigate to my site. Although I can navigate to the statics folder. My Apache config and wsgi script look like the following...
lbirdf.wsgi
import os
import sys
sys.path.append('/home/lbi/rdfweb/web')
sys.path.append('/home/lbi/rdfweb/web/lbirdf')
os.environ['DJANGO_SETTINGS_MODULE'] = 'lbirdf.settings_production'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
Apache config
Listen 8080
<VirtualHost *:8080>
ServerName server1
WSGIScriptAlias /rdfweb /home/lbi/rdfweb/web/lbirdf/apache/lbirdf.wsgi
Alias /statics /home/lbi/rdfweb/web/lbirdf/statics
Alias /admin_media /home/lbi/rdfweb/web/lbirdf/admin_media
<Directory /home/lbi/rdfweb/web/lbirdf/apache>
Order allow,deny
Allow from all
</Directory>
<Directory /home/lbi/rdfweb/web/lbirdf/admin_media>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Any ideas on where I might be going wrong?
What messages are in the Apache error log? Try setting DEBUG to true in Django settings file to get more informative error message sent back to browser in instance that it is an issue in your application.
Possible causes are, urls.py is wrong because you are erroneously including site prefix when you don't need to or a permissions issue because code running as Apache user and not you.
Not knowing the actual errors doesn't help in working out the problem.
Try:
sys.path.append('/home/lbi/rdfweb/')