一台服务器上有两个站点:NameVirtualHost site2没有VirtualHosts

时间:2022-10-06 08:03:24

I have two web sites developed with Django framework and I've tried to get them reachable from the same machine with virtual host configuration in Apache2. I have created /etc/apache2/sites-available/alcs:

我有两个使用Django框架开发的网站,我试图通过Apache2中的虚拟主机配置从同一台机器*问它们。我创建了/ etc / apache2 / sites-available / alcs:

NameVirtualHost alcs:80
<VirtualHost alcs:80>
    ServerAdmin candini@meeo.it
    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>

and /etc/apache2/sites-available/jsonopenlayers:

NameVirtualHost jsonopenlayers:80
<VirtualHost jsonopenlayers:80>
    ServerAdmin candini@meeo.it
    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>

Then I have made the following:

然后我做了以下事情:

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

But the problem is that I get:

但问题是我得到:

root@office-007:~# /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

Only alcs site is properly reached at http://localhost/alcs. If I try to reach the second one I get the following Django error:

在http:// localhost / alcs中只能正确访问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.

But it works without problems if I delete alcs link from /etc/apache2/sites-enabled/ directory.

但是如果从/ etc / apache2 / sites-enabled /目录中删除alcs链接,它可以正常工作。

Where my configuration is wrong?

我的配置错在哪里?

1 个解决方案

#1


1  

As I mentioned in the comments, named hosts is completely the wrong way to go about this. Named hosts are exactly that - when you want to serve several different domain names from the same machine. So if you wanted to serve foo.com and bar.com from the same Apache, you would use this.

正如我在评论中提到的那样,命名主机完全是错误的方法。命名主机就是这样 - 当您想要从同一台机器上提供多个不同的域名时。因此,如果您想从同一个Apache提供foo.com和bar.com,您可以使用它。

What you want is something different, and much simpler: just to serve two Django sites off separate sub-folders in the same domain. You can do that with just two lines:

你想要的是不同的东西,更简单:只是为了在同一个域中的不同子文件夹中提供两个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

#1


1  

As I mentioned in the comments, named hosts is completely the wrong way to go about this. Named hosts are exactly that - when you want to serve several different domain names from the same machine. So if you wanted to serve foo.com and bar.com from the same Apache, you would use this.

正如我在评论中提到的那样,命名主机完全是错误的方法。命名主机就是这样 - 当您想要从同一台机器上提供多个不同的域名时。因此,如果您想从同一个Apache提供foo.com和bar.com,您可以使用它。

What you want is something different, and much simpler: just to serve two Django sites off separate sub-folders in the same domain. You can do that with just two lines:

你想要的是不同的东西,更简单:只是为了在同一个域中的不同子文件夹中提供两个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