2011-12-12 58 views
1

我有两个使用Django框架开发的网站,我试图让它们可以在同一台机器上使用Apache2中的虚拟主机配置访问。 我创建的/ etc/apache2的/网站可用/美联冠军赛一个服务器上的两个站点:NameVirtualHost site2没有虚拟主机

NameVirtualHost alcs:80 
<VirtualHost alcs:80> 
    ServerAdmin [email protected] 
    ServerName alcs 
    DocumentRoot /home/candini/Repos/ALCS/SW/alcs-system/GUI-User-Interface 
    <Directory /> 
     Options FollowSymLinks 
     AllowOverride None 
    </Directory> 
    <Directory /home/candini/Repos/ALCS/SW/alcs-system/GUI-User-Interface/> 
     Options Indexes FollowSymLinks MultiViews 
     AllowOverride None 
     Order allow,deny 
     allow from all 
    </Directory> 
    WSGIScriptAlias//home/candini/Repos/ALCS/SW/alcs-system/GUI-User-Interface/apache/django.wsgi 
    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ 
    <Directory "/usr/lib/cgi-bin"> 
     AllowOverride None 
     Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch 
     Order allow,deny 
     Allow from all 
    </Directory> 
    ErrorLog ${APACHE_LOG_DIR}/error.log 
    LogLevel warn 
    CustomLog ${APACHE_LOG_DIR}/access.log combined 
    Alias /doc/ "/usr/share/doc/" 
    <Directory "/usr/share/doc/"> 
     Options Indexes MultiViews FollowSymLinks 
     AllowOverride None 
     Order deny,allow 
     Deny from all 
     Allow from 127.0.0.0/255.0.0.0 ::1/128 
    </Directory> 
</VirtualHost> 

的/ etc/apache2的/网站可用/ jsonopenlayers

NameVirtualHost jsonopenlayers:80 
<VirtualHost jsonopenlayers:80> 
    ServerAdmin [email protected] 
    ServerName jsonopenlayers 
    DocumentRoot /home/candini/Repos/CanetaRepo/tmp/STO 
    <Directory /> 
     Options FollowSymLinks 
     AllowOverride None 
    </Directory> 
    <Directory /home/candini/Repos/CanetaRepo/tmp/STO/> 
     Options Indexes FollowSymLinks MultiViews 
     AllowOverride None 
     Order allow,deny 
     allow from all 
    </Directory> 
    WSGIScriptAlias//home/candini/Repos/CanetaRepo/tmp/STO/apache/django.wsgi 
    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ 
    <Directory "/usr/lib/cgi-bin"> 
     AllowOverride None 
     Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch 
     Order allow,deny 
     Allow from all 
    </Directory> 
    ErrorLog ${APACHE_LOG_DIR}/error.log 
    LogLevel warn 
    CustomLog ${APACHE_LOG_DIR}/access.log combined 
    Alias /doc/ "/usr/share/doc/" 
    <Directory "/usr/share/doc/"> 
     Options Indexes MultiViews FollowSymLinks 
     AllowOverride None 
     Order deny,allow 
     Deny from all 
     Allow from 127.0.0.0/255.0.0.0 ::1/128 
    </Directory> 
</VirtualHost> 

然后我做了以下:

echo "127.0.0.1 localhost.localdomain localhost jsonopenlayers alcs" >> /etc/hosts 
a2ensite alcs 
a2ensite jsonopenlayers 
/etc/init.d/apache2 reload 
/etc/init.d/apache2 restart 

但问题是,我得到:

[email protected]:~# /etc/init.d/apache2 restart 
* Restarting web server apache2 [Mon Dec 12 11:23:26 2011] [warn] NameVirtualHost jsonopenlayers:80 has no VirtualHosts 
[Mon Dec 12 11:23:26 2011] [warn] NameVirtualHost jsonopenlayers:80 has no VirtualHosts 
... waiting [Mon Dec 12 11:23:27 2011] [warn] NameVirtualHost jsonopenlayers:80 has no VirtualHosts 
[Mon Dec 12 11:23:27 2011] [warn] NameVirtualHost jsonopenlayers:80 has no VirtualHosts 

只有alcs站点正确到达http://localhost/alcs。如果我试图达到第二个我收到以下错误的Django:

Page not found (404) 
Request Method: GET 
Request URL: http://localhost/jsonopenlayers/ 

Using the URLconf defined in python_scripts.urls, Django tried these URL patterns, in this order: 
^alcs/ 
^alcs/evolution_model_catalogue.html 
^alcs/advanced_search_option.html 
^alcs/ontological_tree_cascade.html 
^alcs/search_evolution_model.html 
^alcs/load_evolution_model.json 
^alcs/select_load_option.html 
^alcs/delete_model.json 
^alcs/withdraw_model.json 
^alcs/evolution_model_catalogue.html 
^alcs/support_request.json 
^alcs/malfunction_report.json 
^alcs/file_upload.html 
^alcs/malfunction_file_upload 

The current URL, jsonopenlayers/, didn't match any of these. 

但是,如果我从的/ etc/apache2的/删除美联冠军赛链接它的工作原理没有问题的网站启用/目录。

我的配置错了?

+0

如果你想让你的网站在'localhost/sitename'上,你为什么要使用命名主机?这完全与它无关。 –

+0

是的,我只想让我的网站在http:// localhost/alcs和http:// localhost/jsonopenlayers中可以访问。那么如何实现这一目标呢? – caneta

回答

1

正如我在评论中提到的,命名主机完全是错误的方式去做这件事。命名主机就是这样 - 当你想从同一台机器提供几个不同的域名。所以如果你想从同一个Apache服务foo.com和bar.com,你可以使用它。

你想要什么是不同的,更简单:只需要​​在同一个域中的两个Django站点单独的子文件夹。你可以用两行来做到这一点:

WSGIScriptAlias /alcs/ /home/candini/Repos/ALCS/SW/alcs-system/GUI-User-Interface/apache/django.wsgi 
WSGIScriptAlias /jsonopenlayers/ /home/candini/Repos/CanetaRepo/tmp/STO/apache/django.wsgi 
相关问题