创建子域名导致 DNS 错误

创建子域名导致 DNS 错误

我目前有一个网站:“www.mydomain.com”,并想创建一个名为“test.mydomain.com”的子域名。

我执行了以下步骤,但遇到了 2 个错误:

1)当我访问“test.mydomain.com”时,出现 DNS 错误。

2)当我运行“sudo /etc/init.d/apache2 reload”时,我收到以下错误消息:

Reloading web server config apache2 apache2: Could not reliably determine the 
server's fully qualified domain name, using X.Y.X.Y for ServerName

以下是我所做的更改:

1)/etc/hosts文件:

127.0.0.1 localhost localhost.localdomain
X.Y.X.Y www.mydomain.com test.mydomain.com

2)/etc/apache2/sites-available/test.mydomain.com 文件:

<VirtualHost *:80>
    ServerName test.mydomain.com
    ServerAlias www.test.mydomain.com
    DocumentRoot /var/test/                  
</VirtualHost>
<Directory /var/test/>
        Options Indexes FollowSymLinks MultiViews +Includes
        AllowOverride None
        Order allow,deny
        allow from all
</Directory>
3) /etc/apache2/sites-available/www.mydomain.com file:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost

    ServerName www.mydomain.com
    DocumentRoot /var/www
    <Directory />
        Options FollowSymLinks
        AllowOverride FileInfo
    </Directory>
    <Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride FileInfo
        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 /var/log/apache2/error.log

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

    CustomLog /var/log/apache2/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>

3)我在 /etc/apache2/sites-available/default 文件中添加了以下行:

ServerName www.mydomain.com

4)运行以下命令

sudo a2ensite www.mydomain.com
sudo a2ensite test.mydomain.com
sudo /etc/init.d/apache2 reload

答案1

DNS 错误发生在客户端。您在哪里编辑了“/etc/hosts”?您应该在客户端(浏览器所在的 PC)上编辑它。

如果问题出在 apache 上,您可能会收到 404 错误或类似错误,而不是 DNS 错误。

相关内容