当前的URL与任何这些网站都不匹配 - 使用多个网站

时间:2011-06-29 17:21:49

标签: django apache mod-wsgi wsgi django-wsgi

我希望有多个django安装。一个在/(工作正常)和一个在/亚当。斜杠adam中的那个正确地被apache重定向,直到你尝试访问一个应用程序。例如。 / admin有效但/ adam / admin不起作用。我收到错误:

Page not found (404)
Request Method: GET
Request URL:    http://[CENSORED]/adam/
Using the URLconf defined in bms.urls, Django tried these URL patterns, in this order:
^admin/doc/
^admin/
The current URL, , didn't match any of these.

注意空的逗号。 apache虚拟主机是:

<VirtualHost *:80>

    ServerName [CENSORED]
    DocumentRoot /home/user/bms

    Alias /static/admin/ /usr/local/lib/python2.7/site-packages/Django-1.3-py2.7.egg/django/contrib/admin/media/

    <Directory /home/user/bms/apache>
        Order allow,deny
        Allow from all
    </Directory>

    <Directory /home/ajt1g09/bms/apache>
        Order allow,deny
        Allow from all
    </Directory>

    WSGIDaemonProcess bms user=user group=user processes=2 threads=25 python-path=/usr/local/lib/python2.7/site-packages
    WSGIProcessGroup bms
    WSGIScriptAliasMatch ^/adam(.*) /home/ajt1g09/bms/apache/django.wsgi
    WSGIScriptAlias / /home/user/bms/apache/django.wsgi

</VirtualHost>

ajt1g09 / bms / apache中的django.wsgi文件:

import os
import sys

path = '/home/ajt1g09/bms'
if path not in sys.path:
    sys.path.append(path)

sys.path.append('/usr/local/lib/python2.7/site-packages')
sys.path.append('/home/ajt1g09')

os.environ['DJANGO_SETTINGS_MODULE'] = 'bms.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

最后,ajt1g09 / bms中的urls.py文件(显示/ admin就在那里):

  

来自django.conf.urls.defaults导入   模式,包括,网址

     

#Uncomment接下来的两行来启用admin:来自django.contrib   导入管理员   admin.autodiscover()

     

urlpatterns = patterns('',       # 例子:       #url(r'^ $','bms.views.home',name ='home'),       #url(r'^ bms /',include('bms.foo.urls')),

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

# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)), )

我不知道问题是什么。

1 个答案:

答案 0 :(得分:2)

您不应该使用:

WSGIScriptAliasMatch ^/adam(.*) /home/ajt1g09/bms/apache/django.wsgi

只需使用:

WSGIScriptAlias /adam /home/ajt1g09/bms/apache/django.wsgi

WSGIScriptAliasMatch将无法正常工作,因为您尚未将匹配的部分替换回最后一个参数。即,

WSGIScriptAliasMatch ^/adam(.*) /home/ajt1g09/bms/apache/django.wsgi$1

您应该只是不使用WSGIScriptAliasMatch。这仅适用于高级用例,并且要求您在使用它时要非常小心,因为如何使用它会影响SCRIPT_NAME / PATH_INFO在传递给应用程序时设置的内容,而urls.py匹配基于此。

相关问题