Apache:配置虚拟主机

时间:2012-08-27 14:55:03

标签: apache2

我在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 /主机

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

我需要使用第二个VirtualHost条目匹配发送到此服务器的所有请求,但使用此域名“mydomain.site.ch”的条目除外。 但结果是:使用此配置,我得到第一个VirtualHost条目处理的所有请求..(配置语法没问题!)有关如何解决此问题的任何想法?

1 个答案:

答案 0 :(得分:1)

以这种方式改变它:

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>

如果这无济于事,请尝试下一步:

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>

更新 - /etc/hosts

如果您想使用localhost VirtualHost提供来自外部的请求,则可能必须在/etc/hosts中明确设置:

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

然后尝试在浏览器中打开:

http://mydomain.site.chhttp://x.y.z.89/