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

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

问题描述

我有一个Django项目,我需要安装在我的url的两个不同的子目录,我需要Wordpress运行在/。所以:

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

这是我到目前为止的httpd.conf: / p>

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

AddType应用程序/ x-httpd-php .php
DocumentRoot / var / empty

别名/ site_media / / home / zach / projects / python / myproject / static /
别名/媒体/ /home/zach/projects/python/myproject/env/lib/python2.6/site-packages/django / contrib / admin / media /
别名/ / 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

<目录/ home / zach / projects / python / myproject / app>
订单允许,拒绝
允许从所有
< / Directory>

<目录/ home / zach / projects / python / myproject / wordpress>
订单允许,拒绝
允许从所有
< / Directory>



在我添加配置WordPress,Django应用程序正常工作。但是通过这个新设置,我可以看到WordPress安装在/,但Django应用程序没有得到满足。我在Apache配置中是一个noob - 我缺少什么?

解决方案

替换:

  DocumentRoot / var / empty 

与:

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

删除:

 别名/ / 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。



WSGIScriptAl iasMatch是如此,Django本身认为它仍然安装在根网站,即使其中仅提名的子URL实际上是通过的。这简化了urls.py的工作。



请注意,WSGI脚本路径结束时的$ 1非常重要,因此请勿将其关闭。


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?

解决方案

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.

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

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