Apache 虚拟主机子域名

Apache 虚拟主机子域名

我在 000-default 文件中有 2 个条目。其中一个是关于子域的,另一个是关于其他所有内容的。问题是只有一个有效,文件中的第一个是什么。因此,如果我先写有效的子域条目,然后写另一个,那么它就有效了。

<VirtualHost *:80>
        ServerAdmin webmaster@localhost

        DocumentRoot /var/www
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>

        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

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride All
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

    <Location /svn>
    DAV svn
    SVNParentPath /home/svn
    AuthType Basic
    AuthName "Your repository name"
    AuthUserFile /etc/subversion/passwd
    Require valid-user
    SVNPathAuthz On
#   SVNAdvertiseV2Protocol Off
    </Location>
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName  sub.domain.com
    ServerAlias sub.domain.com

    DocumentRoot /var/www/sub.domain
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /var/www/sub.domain/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride All
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

RewriteEngine On

答案1

尝试在虚拟主机配置的顶部使用 NameVirtualHost *:80。

答案2

对我来说,两者工作正常 ServerAdmin webmaster@localhost ServerName puppetmaster.matrix.nx DocumentRoot /var/www/html Options FollowSymLinks AllowOverride None Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all

服务器管理员 webmaster@localhost 服务器名称 puppet.matrix.nx 服务器别名 puppet.matrix.nx

DocumentRoot /var/www/sub.domain
<Directory />
    Options FollowSymLinks
    AllowOverride None
</Directory>
<Directory /var/www/sub.domain/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
</Directory>

[root@puppetmaster conf.d]# 获取 http://puppetmaster.matrix.nx/ 测试页面1

[root@puppetmaster conf.d]# 获取 http://puppet.matrix.nx/ 测试页面2

相关内容