多个域都使用Django WSGI错误地指向同一个VirtualHost

时间:2012-01-18 10:14:56

标签: django apache wsgi virtualhost

我正在使用wsgi运行Django。我有两个域和一个子域指向三个单独的apache2虚拟主机。对于某些(可能非常明显)原因,每个域都登陆到同一个站点(第一个使用a2iteite在线放置)。我的配置如下:

<VirtualHost *:80>
   ServerName www.one.com/
   ServerAlias one.com
   ServerAdmin andy@one.com

   DocumentRoot /srv/www/one.com/public_html

   <Directory /srv/www/one.com/application>
      Order allow,deny
      Allow from all
   </Directory>

   WSGIDaemonProcess one.com processes=2 threads=15 display-name=%{GROUP}
   WSGIProcessGroup one.com
   WSGIScriptAlias / /srv/www/one/application/apache/one.wsgi

   Alias /robots.txt /srv/www/one.com/public_html/robots.txt
   Alias /favicon.ico /srv/www/one.com/public_html/favicon.ico
   Alias /media /srv/www/one.com/public_html/media
   Alias /static /srv/www/one.com/public_html/static

   ErrorLog /srv/www/one.com/logs/error.log
   CustomLog /srv/www/one.com/logs/access.log combined   

</VirtualHost>

////// /// one.wsgi //////////

import os
import sys

sys.path.append('/srv/www/one.com/application')

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

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

//////////////////

<VirtualHost *:80>
   ServerName dev.one.co.uk/
   ServerAlias www.dev.one.co.uk/
   ServerAdmin andy@one.com

   DocumentRoot /srv/www/dev.one.com/public_html


   <Directory /srv/www/dev.one.com/application>
      Order allow,deny
      Allow from all
   </Directory>

   WSGIScriptAlias / /srv/www/dev.one.com/application/apache/devone.wsgi

   Alias /robots.txt /srv/www/dev.one.com/public_html/robots.txt
   Alias /favicon.ico /srv/www/dev.one.com/public_html/favicon.ico
   Alias /media /srv/www/dev.one.com/public_html/media
   Alias /static /srv/www/dev.one.com/public_html/static

   ErrorLog /srv/www/dev.one.com/logs/error.log
   CustomLog /srv/www/dev.one.com/logs/access.log combined   

</VirtualHost>

//////// devone.wsgi ///////////

import os
import sys

sys.path.append('/srv/www/dev.one.com/application')

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

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

/////////////

<VirtualHost *:80>
   ServerName dev.two.com/
   ServerAlias www.dev.two.com/
   ServerAdmin andy@two.com

   DocumentRoot /srv/www/dev.two.com/public_html


   <Directory /srv/www/dev.two.com/application>
      Order allow,deny
      Allow from all
   </Directory>

   WSGIScriptAlias / /srv/www/dev.two.com/application/apache/devtwo.wsgi

   Alias /robots.txt /srv/www/dev.two.com/public_html/robots.txt
   Alias /favicon.ico /srv/www/dev.two.com/public_html/favicon.ico
   Alias /media /srv/www/dev.two.com/public_html/media
   Alias /static /srv/www/dev.two.com/public_html/static

   ErrorLog /srv/www/dev.two.com/logs/error.log
   CustomLog /srv/www/dev.two.com/logs/access.log combined   

</VirtualHost>

//////// devtwo.wsgi /////

import os
import sys

sys.path.append('/srv/www/dev.two.com/application')

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

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

域名都在我的服务器IP上正常,但它们都落在同一页面上。我错过了什么?提前谢谢!

更新

NameVirtualHost *:80

在ports.conf中声明

1 个答案:

答案 0 :(得分:1)

  • 确保按顺序加载vhosts定义,从最具体到最不具体(例如,可能通过命名10_dev.two.com.conf20_dev.one.com.conf30_one.com.conf
  • ServerNameServerAlias指令不应包含/