Apache mit mod_python oder mod_wsgi?

Django, Flask, Bottle, WSGI, CGI…
Antworten
FrankTheFox
User
Beiträge: 13
Registriert: Montag 18. Juli 2011, 11:37

Hi,

ich möchte meine Webseiten nicht über den Entwicklungsserver in Django laufen lassen ( runserver..) sondern den Apache als Server nutzen und die Seiten als Produktivsystem laufen lassen.
Ich bin mir aber nicht sicher ob ich mod_python oder eben mod_wsgi nutzen soll. :K
Ich nutze in meinem Projekt im dem Projektverzeichniss "media" und "templates" für css und html Dateien.
Muss ich den ".py" Dateien Anpassungen vornehmen?

OS = ubuntu
deets

mod_wsgi ist die Wahl, AFAIK ist mod_python noch nicht mal mehr gewartet.
Benutzeravatar
/me
User
Beiträge: 3555
Registriert: Donnerstag 25. Juni 2009, 14:40
Wohnort: Bonn

FrankTheFox hat geschrieben:ich möchte meine Webseiten nicht über den Entwicklungsserver in Django laufen lassen ( runserver..) sondern den Apache als Server nutzen und die Seiten als Produktivsystem laufen lassen.
Ich bin mir aber nicht sicher ob ich mod_python oder eben mod_wsgi nutzen soll.
Dann zitiere ich mal aus der Django-Dokumentation:
"mod_python support: The mod_python library has not had a release since 2007 or a commit since 2008. The Apache Foundation board voted to remove mod_python from the set of active projects in its version control repositories, and its lead developer has shifted all of his efforts toward the lighter, slimmer, more stable, and more flexible mod_wsgi backend."
FrankTheFox
User
Beiträge: 13
Registriert: Montag 18. Juli 2011, 11:37

Hi , danke für den Tipp.
Ok, habe das wsgi Module installiert und geladen. Apache neu gestartet.


default Datei dann geändert...
<Directory />
Options Indexes FollowSymLinks MultiViews ExecCGI

AddHandler cgi-script .cgi
AddHandler wsgi-script .wsgi

AllowOverride None
Order allow,deny
allow from all
</Directory>

Wobei ich aber nicht weiss,wie ich jetzt Django und den Apache richtig konfiguruere, das ich mein Projekt ohne runserver laufen lassen kann.


Gruß
Franky
Benutzeravatar
/me
User
Beiträge: 3555
Registriert: Donnerstag 25. Juni 2009, 14:40
Wohnort: Bonn

FrankTheFox hat geschrieben:Wobei ich aber nicht weiss,wie ich jetzt Django und den Apache richtig konfiguruere, das ich mein Projekt ohne runserver laufen lassen kann.
Ich bemühe mich, die WSGI-Datei, auf die der Apache-Eintrag WSGIScriptAlias verweist, möglichst flexibel zu gestalten. Bei mir liegt sie im Ordner "wsgi" unterhalb des Anwendungsordners und hat grundlegend folgenden Inhalt

Code: Alles auswählen

import os.path
import sys

app_dir = os.path.realpath(os.path.join(os.path.dirname(__file__), ".."))
appname = app_dir.split(os.path.sep)[-1:][0]
main_dir = os.path.realpath(os.path.join(app_dir, ".."))

if main_dir not in sys.path:
    sys.path.append(main_dir)

if app_dir not in sys.path:
    sys.path.append(app_dir)

os.environ['DJANGO_SETTINGS_MODULE'] = appname + '.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
Mit diesem dynamischen Aufbau kann ich die Anwendung dann beliebig in der Ordnerstruktur platzieren ohne die Konfiguration anpassen zu müssen.
FrankTheFox
User
Beiträge: 13
Registriert: Montag 18. Juli 2011, 11:37

Danke für die Antworten!

ich habe jetzt mein Projekt auf einen FreeBSD Server gepackt. Aber ich habe den Eindruck das ich mir die Funktionalität mehr als zusammengewurschtelt habe.

Auszüge aus meiner "httpd.conf"
...
LoadModule wsgi_module libexec/apache22/mod_wsgi.so
...
mod_wsgi wird geladen...

dann
<VirtualHost xxx.xxx.xxx.xxx:80>
Alias /media /usr/home/devel/WebPortalApp/WebPortal/media
WSGIScriptAlias / /usr/home/devel/WebPortalApp/WebPortal/wsgi/django.wsgi



DirectoryIndex index.html
DocumentRoot /usr/home/devel/WebPortalApp/WebPortal/templates/

LogLevel warn

# WSGIDaemonProcess myHost processes=1 maximun-requests=1000 threads=1
# WSGIProcessGroup myHost

<Directory />
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>

<Directory /usr/home/devel/WebPortalApp/WebPortal/ >
Options Indexes FollowSymLinks MultiViews +ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>


vor Loadmodule Bereich habe ich dann unter anderem noch ServerName mit xxx.xxx.xxx.xxx und ServerRoot mit "/usr/local".


Python wird auf dem Server gefunden. Datenbank ist angelegt.


django.wsgi Datei:
import os
import sys

os.environ['PYTHON_EGG_CACHE'] = '/tmp'

sys.stdout = sys.stderr

app_dir=os.path.realpath(os.path.join(os.path.dirname(__file__),".."))
appname=app_dir.split(os.path.sep)[-1:][0]
main_dir=os.path.realpath(os.path.join(app_dir,".."))

if main_dir not in sys.path:
sys.path.append(main_dir)

if app_dir not in sys.path:
sys.path.append(app_dir)

os.environ['DJANGO_SETTINGS_MODULE'] = appname + '.settings'

import django.core.handlers.wsgi
application=django.core.handlers.wsgi.WSGIHandler()
os.environ['PYTHON_EGG_CACHE'] = '/tmp'
ist drin, weil ich einen Fehler bekam "[erno 13]...." Egg konte nicht geschrieben werden.

Sieht das aus wie eine sinnvolle Servererinrichtung oder habe ich was vergessen?

Was mich wundert ist, obwohl ich "WSGIDaemonProcess" und "WSGIProcessGroup" auskommentiert habe, wird
das Django Framework ausgeführt.

mit:

views.py
from django.shortcuts import render_to_response
from django.http import HttpResponse

def WebPortalStartApp(request):
return HttpResponse("Hi Welt")
urls.py
from django.conf.urls.defaults import *
from WebPortal import settings
from WebPortal import views
#from django.contrib import admin
#admin.autodiscover()

urlpatterns = patterns('',
(r'^$', views.WebPortalStartApp),

# Uncomment the admin/doc line below to enable admin documentation:
# (r'^admin/doc/', include('django.contrib.admindocs.urls')),

# Uncomment the next line to enable the admin:
#(r'^admin/', include(admin.site.urls)),
)
und die settings.py Einträge
....
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)
...

ROOT_URLCONF = 'WebPortal.urls'

PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
...
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.admin',
'WebPortal',
# Uncomment the next line to enable the admin:
...
LOGIN_REDIRECT_URL = '/'


Gruß
Franky
Antworten