开发者

I need help on configuring mod_wsgi and Django

开发者 https://www.devze.com 2023-01-29 21:51 出处:网络
Apache & mod_wsgi are configured correctly (I\'ve created a hello world .html apache file and a hello world mod_wsgi application with

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
0

精彩评论

暂无评论...
验证码 换一张
取 消