Virtualhost:AH00558:apache2:无法可靠地确定服务器的完全限定域名

Virtualhost: AH00558: apache2: Could not reliably determine the server's fully qualified domain name

每当我尝试在 Debian 10 上使用 apache 设置虚拟主机时遇到问题。

我正在尝试在地址 products.crud 上设置虚拟主机。所以目录结构是var/www/products.crub/web.

因此,我在 /etc/apache2/sites-available 目录中创建了 Apache Virtual Hosts 配置文件,我是否也可以在 /etc/apache2/sites-enabled 目录中启用它。名为 products.crud.conf 的文件的内容是:

<VirtualHost *:80>
ServerName products.crud
DocumentRoot /var/www/products.crud/web
<Directory /var/www/products.crud/web>
    RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule . index.php [L]
</Directory>

所以,我启用了域:

$ sudo a2ensite products.crud

然后我使用

测试了语法

$ sudo apachectl configtest

问题是我收到这个错误:

AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using fe80::2ff5:a177:ff45:30b3. Set the 'ServerName' directive globally to suppress this message Syntax OK

我尝试解决问题的方法

我尝试在 /etc/hosts

中添加域
127.0.0.1   localhost
#127.0.1.1  terminale
#127.0.0.1  products.test
127.0.0.5   products.crud

我也试过在apache2.conf中添加:

# Global configuration                                                          
#                                                                               
ServerName products.crud
#                                                                               
# ServerRoot: The top of the directory tree under which the server's            
# configuration, error, and log files are kept.                                 
#   

每当我尝试连接到 products.crud 时,我看到的是 apache 的本地主机主页,而不是我的 index.php。我该如何解决?

如果您将 products.crud.conf 文件中的 ServerName products.test 更改为 ServerName products.crud 会怎样,如下所示:

  <VirtualHost *:80>
    ServerName products.crud
    DocumentRoot /var/www/products.crud/web
    <Directory /var/www/products.crud/web>
        RewriteEngine On
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule . index.php [L]
    </Directory>
 </VirtualHost>

如果你去: /etc/apache2/apache2.conf 并插入: 服务器名称本地主机 然后在终端中输入以下命令重新启动 apache: sudo systemctl reload apache2

参考 https://codeinfopark.com/questions/ah00558-apache2-could-not-reliably-determine-the-servers-fully-qualified-domain-name-using-172-18-0-3-set-the-servername-directive-globally-to-suppress-this-message/