Django (wsgi) and Wordpress coexisting in Apache virtualhost

时光总嘲笑我的痴心妄想 提交于 2019-12-17 10:56:57

问题


I have a Django project that I need mounted at two different subdirectories of my url, and I need Wordpress running at /. So:

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

Here's the httpd.conf that I have so far:

<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>

Before I added the config for WordPress, the Django app was working fine. But with this new setup I am able to see the WordPress install at /, but the Django app isn't getting served. I'm sort of a noob at Apache config - what am I missing?


回答1:


Replace:

DocumentRoot /var/empty

with:

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

Remove:

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

Replace:

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

with:

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

In other words, use DocumentRoot to refer to wordpress that needs to be at root of site and not Alias directive.

The WSGIScriptAliasMatch is so Django itself thinks it is still mounted at root site even though only nominated sub URLs of it are actually passed through. This simplifies things for urls.py.

Note that the $1 at end of WSGI script path is important, so don't leave it off.




回答2:


Paging Graham Dumpleton :)

I'd venture a guess that the line

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

overrides everything below it. Therefore any requests to /accounts will be processed by the wordpress application rather than by the Django application.

From the documentation:

Mounting At Root Of Site

If instead you want to mount a WSGI application at the root of a site, simply list '/' as the mount point when configuring the WSGIScriptAlias directive.

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

Do note however that doing so will mean that any static files contained in the DocumentRoot will be hidden and requests against URLs pertaining to the static files will instead be processed by the WSGI application.



来源:https://stackoverflow.com/questions/3534678/django-wsgi-and-wordpress-coexisting-in-apache-virtualhost

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!