0

我在 Apache 2.2.3 CentOS 中配置虚拟主机时遇到了一些麻烦,我有以下配置:

httpd.conf

NameVirtualHost mydomain.site.ch

<VirtualHost mydomain.site.ch>
    ServerName mydomain.site.ch
    DocumentRoot /home/django_www/hello
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot /var/www/html
</VirtualHost>

/etc/hosts

127.0.0.1       localhost.localdomain localhost
x.y.z.89        mydomain.site.ch

我需要将到达该服务器的所有请求与第二个 VirtualHost 条目匹配,但带有此域名的请求除外 "mydomain.site.ch" 。但结果是:通过这个配置,我得到了第一个 VirtualHost 条目处理的所有请求..(配置语法没问题!)关于如何纠正这个问题的任何想法?

4

1 回答 1

1

Change it in this way:

NameVirtualHost *:80

<VirtualHost *:80>
    ServerName mydomain.site.ch
    DocumentRoot /home/django_www/hello
    WSGIScriptAlias / /home/django_www/hello/django.wsgi

    <Directory /home/django_www/hello>
        Options FollowSymLinks MultiViews
        Order deny,allow
        Allow from all
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot /var/www/html

    <Directory /home/www/html>
        Options FollowSymLinks MultiViews
        AllowOverride all
        Order deny,allow
        Allow from all
    </Directory>
</VirtualHost>

If this will not help then try next:

NameVirtualHost *:80

<VirtualHost x.y.z.89:80>
    ServerName mydomain.site.ch
    DocumentRoot /home/django_www/hello
    WSGIScriptAlias / /home/django_www/hello/django.wsgi

    <Directory /home/django_www/hello>
        Options FollowSymLinks MultiViews
        Order deny,allow
        Allow from all
    </Directory>
</VirtualHost>

<VirtualHost 127.0.0.1:80>
    ServerName localhost
    DocumentRoot /var/www/html

    <Directory /home/www/html>
        Options FollowSymLinks MultiViews
        AllowOverride all
        Order deny,allow
        Allow from all
    </Directory>
</VirtualHost>

UPDATE - /etc/hosts

If you want to serve the requests from outside with your localhost VirtualHost, you'll might have to set it explicitly in /etc/hosts:

127.0.0.1    localhost
x.y.z.89     localhost
x.y.z.89     mydomain.site.ch

Then try to open in browser:

http://mydomain.site.ch and http://x.y.z.89/

于 2012-08-27T15:41:52.307 回答