Apache 主站点不断重定向到虚拟主机

Apache 主站点不断重定向到虚拟主机

我有一个带有 Apache 网络服务器的网站,它也托管一些子域。

我面临的问题是,一旦我激活任何虚拟主机,主站点就会不断重定向到我拥有的(唯一的)虚拟主机。

如果我停用虚拟主机,主站点上的一切都可以正常运行,但没有我需要的子域名。

我在 ArchLinux 下使用 apache 2.2.19-1。

我以 mydomain.com 作为主站点,并具有以下 httpd.conf:

ServerRoot "/etc/httpd"
Listen 80

#LoadModule section... a lot of LoadModule I omit

User http
Group http

ServerAdmin [email protected]

ServerName mydomain.com:80

DocumentRoot "/srv/http"

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
</Directory>

<Directory "/srv/http">
    Options FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>

<FilesMatch "^\.ht">
    Order allow,deny
    Deny from all
    Satisfy All
</FilesMatch>

ErrorLog "/var/log/httpd/error_log"

LogLevel warn

<IfModule log_config_module>
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common

    <IfModule logio_module>
      # You need to enable mod_logio.c to use %I and %O
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>
    CustomLog "/var/log/httpd/access_log" combined
</IfModule>

<IfModule alias_module>
    ScriptAlias /cgi-bin/ "/srv/http/cgi-bin/"
</IfModule>

<Directory "/srv/http/cgi-bin">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
</Directory>

DefaultType text/plain

<IfModule mime_module>
    TypesConfig conf/mime.types
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
</IfModule>

# Some included conf files follow, I won't post them, just vhosts, but if needed ask me and I'll post them. As far as I know they aren't relevant
# Multi-language error messages
Include conf/extra/httpd-multilang-errordoc.conf
# Fancy directory listings
Include conf/extra/httpd-autoindex.conf
# Language settings
Include conf/extra/httpd-languages.conf
# User home directories
Include conf/extra/httpd-userdir.conf
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
# Various default settings
Include conf/extra/httpd-default.conf

# Secure (SSL/TLS) connections
Include conf/extra/httpd-ssl.conf
<IfModule ssl_module>
  SSLRandomSeed startup builtin
  SSLRandomSeed connect builtin
</IfModule>

这是我的conf/extra/httpd-vhosts.conf:

NameVirtualHost *:80
Include conf/extra/vhosts/

最后是我的 conf/extra/vhosts/yetonlyvhost.conf

<VirtualHost *:80>
     ServerAdmin [email protected]
     ServerName subdomain.mydomain.com
     ServerAlias subdomain.mydomain.com
     DocumentRoot "/home/myuser/subdomaindir"
     DirectoryIndex indice.html
     ErrorLog "/var/log/httpd/vhost-error_log"
     CustomLog "/var/log/httpd/vhost-access_log" combined

    <Directory "/home/myuser/subdomaindir">
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

(子域名索引必须是名为“indice.html”的文件)

你知道我做错了什么吗?我之前在其他服务器上也做过类似的配置,但后来我失败了,但我很确定这里几乎没问题,但现在我还没发现哪里出了问题……

谢谢你!

答案1

解决方案非常简单:

只需为主主机设置另一个虚拟主机即可。当 Apache 被要求访问未配置的网站时,它会使用默认网站,即虚拟主机列表中的第一个网站……

谢谢!

相关内容