Vhost 在 WSL2 上没有 norking

Vhost 在 WSL2 上没有 norking

我正在尝试通过 WSL 2 在 Ubuntu 上运行一个简单的 LAMP 配置。所以我安装了 Apache2、PHP 和 MariaDB。由于它不会在 WSL 上自动启动,我使用此命令启动一切sudo service apache2 start && sudo service mysql start。一切都启动正常,我可以访问localhost,PHP 和 MariaDB 运行良好。但是,当我尝试添加 Vhost 时,它运行得并不好。所以,这是 Apache 配置文件

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        # ServerName eyaka.local

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

<VirtualHost *:80>
        ServerName work.local

        ServerAdmin [email protected]
        DocumentRoot /home/axiol/work

        <Directory />
            Options FollowSymLinks
            AllowOverride all
        </Directory>
        <Directory /home/axiol/work/>
            Options Indexes FollowSymLinks
            AllowOverride all
            Require all granted
        </Directory>


        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn
        SetEnvIf Request_URI "\.(jpg|xml|png|gif|ico|js|css|swf|js?.|css?.)$" D$

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined env=!DontLog
</VirtualHost>

<VirtualHost *:80>
        ServerName perso.local

        ServerAdmin [email protected]
        DocumentRoot /home/axiol/perso

        <Directory />
            Options FollowSymLinks
            AllowOverride all
        </Directory>
        <Directory /home/axiol/perso/>
            Options Indexes FollowSymLinks
            AllowOverride all
            Require all granted
        </Directory>


        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn
        SetEnvIf Request_URI "\.(jpg|xml|png|gif|ico|js|css|swf|js?.|css?.)$" D$

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined env=!DontLog
</VirtualHost>

<VirtualHost *:80>
        ServerName adminer.local

        ServerAdmin [email protected]
        DocumentRoot /home/axiol/adminer

        <Directory />
            Options FollowSymLinks
            AllowOverride all
        </Directory>
        <Directory /home/axiol/adminer/>
            Options Indexes FollowSymLinks
            AllowOverride all
            Require all granted
        </Directory>


        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn
        SetEnvIf Request_URI "\.(jpg|xml|png|gif|ico|js|css|swf|js?.|css?.)$" D$

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined env=!DontLog
</VirtualHost>

这是 Windowshosts文件

127.0.0.1 work.local
127.0.0.1 perso.local
127.0.0.1 adminer.local

当我尝试访问任何虚拟主机时,页面会加载一段时间,然后重定向到版本https(没有任何东西可以进行此重定向,所有文件夹仅包含一个用于测试的空 HTML 文件),最后页面无法加载。我能做些什么让虚拟主机正常工作?

答案1

好的,我偶然找到了解决方案。结果 Windows 尝试使用 IPV4 ping WSL。因此,您还需要将自定义域附加到本地的 IPV6。要使其工作,文件hosts应如下所示:

127.0.0.1 work.local
::1 work.local
127.0.0.1 perso.local
::1 perso.local
127.0.0.1 adminer.local
::1 adminer.local

相关内容