Django (wsgi) und WordPress koexistieren in Apache Virtualhost

Lesezeit: 2 Minuten

Django wsgi und Wordpress koexistieren in Apache Virtualhost
UrLicht

Ich habe ein Django-Projekt, das ich in zwei verschiedenen Unterverzeichnissen meiner URL bereitstellen muss, und ich brauche WordPress, das unter / läuft. Damit:

*.example.com - WordPress
*.example.com/studio - django
*.example.com/accounts - django

Hier ist die httpd.conf, die ich bisher habe:

<VirtualHost *:80>
    ServerName wildcard.localhost
    ServerAlias *.localhost

    AddType application/x-httpd-php .php
    DocumentRoot /var/empty

    Alias /site_media/ /home/zach/projects/python/myproject/static/
    Alias /media/ /home/zach/projects/python/myproject/env/lib/python2.6/site-packages/django/contrib/admin/media/
    Alias / /home/zach/projects/python/myproject/wordpress/

    WSGIScriptAlias /accounts /home/zach/projects/python/myproject/app/privio.wsgi
    WSGIScriptAlias /studio /home/zach/projects/python/myproject/app/privio.wsgi

    <Directory /home/zach/projects/python/myproject/app>
    Order allow,deny
    Allow from all
    </Directory>

    <Directory /home/zach/projects/python/myproject/wordpress>
    Order allow,deny
    Allow from all
    </Directory>

Bevor ich die Konfiguration für WordPress hinzufügte, funktionierte die Django-App einwandfrei. Aber mit diesem neuen Setup kann ich die WordPress-Installation unter / sehen, aber die Django-App wird nicht bedient. Ich bin ein bisschen ein Noob in der Apache-Konfiguration – was vermisse ich?

1646633349 741 Django wsgi und Wordpress koexistieren in Apache Virtualhost
Graham Dupleton

Ersetzen:

DocumentRoot /var/empty

mit:

DocumentRoot /home/zach/projects/python/myproject/wordpress

Entfernen:

Alias / /home/zach/projects/python/myproject/wordpress/

Ersetzen:

WSGIScriptAlias /accounts /home/zach/projects/python/myproject/app/privio.wsgi
WSGIScriptAlias /studio /home/zach/projects/python/myproject/app/privio.wsgi

mit:

WSGIScriptAliasMatch ^(/(accounts|studio)) /home/zach/projects/python/myproject/app/privio.wsgi$1

Mit anderen Worten, verwenden Sie DocumentRoot, um auf WordPress zu verweisen, das sich im Stammverzeichnis der Website befinden muss, und nicht in der Alias-Direktive.

Das WSGIScriptAliasMatch ist so, dass Django selbst denkt, dass es immer noch auf der Root-Site gemountet ist, obwohl nur nominierte Sub-URLs davon tatsächlich durchgeleitet werden. Dies vereinfacht die Dinge für urls.py.

Beachten Sie, dass das $1 am Ende des WSGI-Skriptpfads wichtig ist, also lassen Sie es nicht weg.

Django wsgi und Wordpress koexistieren in Apache Virtualhost
Manoj Govindan

Paging Graham Dumpleton 🙂

Ich wage eine Vermutung, dass die Linie

Alias / /home/zach/projects/python/myproject/wordpress/

überschreibt alles darunter. Daher alle Anfragen an /accounts wird von der WordPress-Anwendung und nicht von der Django-Anwendung verarbeitet.

Von dem Dokumentation:

Montage im Stammverzeichnis der Website

Wenn Sie stattdessen eine WSGI-Anwendung im Stammverzeichnis einer Website bereitstellen möchten, geben Sie beim Konfigurieren der WSGIScriptAlias-Anweisung einfach „https://stackoverflow.com/“ als Bereitstellungspunkt an.

WSGIScriptAlias / /usr/local/www/wsgi-scripts/myapp.wsgi

Beachten Sie jedoch, dass dadurch alle statischen Dateien, die im DocumentRoot enthalten sind, ausgeblendet werden und Anfragen an URLs, die sich auf die statischen Dateien beziehen, stattdessen von der WSGI-Anwendung verarbeitet werden.

  • Das funktioniert nicht mit virtuellen Hosts. Apache weigert sich: Syntax error on line 3 of /path/to/project/vhost.conf: WSGIPythonPath cannot occur within <VirtualHost> section.

    – nichts101

    18. November 2013 um 22:30 Uhr

963450cookie-checkDjango (wsgi) und WordPress koexistieren in Apache Virtualhost

This website is using cookies to improve the user-friendliness. You agree by using the website further.

Privacy policy