Django (wsgi) 和 Wordpress 共存于 Apache 虚拟主机 [英] Django (wsgi) and Wordpress coexisting in Apache virtualhost

查看:22
本文介绍了Django (wsgi) 和 Wordpress 共存于 Apache 虚拟主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Django 项目,我需要将它安装在我的 url 的两个不同子目录中,并且我需要在/下运行 Wordpress.所以:

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

这是我目前拥有的 httpd.conf:

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>

在我为 WordPress 添加配置之前,Django 应用运行良好.但是通过这个新设置,我可以在/看到 WordPress 安装,但是 Django 应用程序没有得到服务.我在 Apache 配置方面有点菜鸟 - 我错过了什么?

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?

推荐答案

替换:

DocumentRoot /var/empty

与:

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

删除:

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

与:

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

换句话说,使用 DocumentRoot 来引用需要位于站点根目录而不是 Alias 指令的 wordpress.

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

WSGIScriptAliasMatch 使 Django 本身认为它仍然安装在根站点,即使实际上只传递了它的指定子 URL.这简化了 urls.py 的事情.

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.

请注意,WSGI 脚本路径末尾的 $1 很重要,所以不要省略它.

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

这篇关于Django (wsgi) 和 Wordpress 共存于 Apache 虚拟主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆