如何在 xampp 中启用虚拟主机

问题描述

我在 Xampp 上配置了虚拟主机,以便我可以运行高级 Yii2 项目(带有前端和后端应用程序),我遵循了 this instruction 和我的httpd-vhosts.conf 看起来像这样

    <VirtualHost *:8081>
    ServerName winnersprimary.ac.tz
    DocumentRoot 'c:\xampp\htdocs\winnersprimary\frontend\web\'
    <Directory 'c:\xampp\htdocs\winnersprimary\frontend\web\'>
            # use mod_rewrite for pretty URL support
            RewriteEngine on
            # If a directory or a file exists,use the request directly
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            # Otherwise forward the request to index.PHP
            RewriteRule . index.PHP

            # use index.PHP as index file
            DirectoryIndex index.PHP

            # ...other settings...
            # Apache 2.4
            Require all granted
            
            ## Apache 2.2
            # Order allow,deny
            # Allow from all
        </Directory>
</VirtualHost> 

    <VirtualHost *:8081>
        ServerName admin.winnersprimary.ac.tz
        DocumentRoot 'c:\xampp\htdocs\winnersprimary\backend\web\'
        <Directory 'c:\xampp\htdocs\winnersprimary\backend\web\'>
                # use mod_rewrite for pretty URL support
                RewriteEngine on
                # If a directory or a file exists,use the request directly
                RewriteCond %{REQUEST_FILENAME} !-f
                RewriteCond %{REQUEST_FILENAME} !-d
                # Otherwise forward the request to index.PHP
                RewriteRule . index.PHP
    
                # use index.PHP as index file
                DirectoryIndex index.PHP
    
                # ...other settings...
                # Apache 2.4
                Require all granted
                
                ## Apache 2.2
                # Order allow,deny
                # Allow from all
            </Directory>
    </VirtualHost>

虽然 apache 主端口是 8081SSL 端口 4433 但它给出了如下图所示的错误error.log 说 {{1}我应该如何解决这个错误?我曾多次尝试更改端口号,但均未成功。

enter image description here

解决方法

在 XAMPP 控制面板上,单击 Shell 下方的资源管理器 (这将打开 xampp 文件资源管理器)

选择并打开 apache 文件夹并转到 conf/extra 文件夹 在 xampp/apache/conf/extra 文件夹中,您要查找的文件名为 httpd-ssl.conf 此文件处理 XAMPP Apache 安装的 SSL 配置。

在任何编辑器中打开 httpd-ssl 文件并搜索 ServerName www.example.com:443

注释掉这一行,只需在它前面添加 # 即可。

接下来,您可以在其正下方的行中添加文本“ServerName Winnersprimary.ac.tz”。

保存并关闭文件

重启 Apache 或 Xampp 控制面板

,

我终于解决了它,我想在这里分享我的解决方案,因为它可能对那里的人有所帮助,我在 xammp shell 上运行 apache_start.bat 并发现它正在编写 {{1} } 以这种方式 DocumentRoot 而不是这种方式 DocumentRoot "c:\xampp\htdocs\winnersprimary\frontend\web\" 注意斜线的区别:) Click here 供参考