Windows 10 上の WSL - localhost は機能しますが、127.0.0.1 は機能しません (ローカル IP ではありません)

Windows 10 上の WSL - localhost は機能しますが、127.0.0.1 は機能しません (ローカル IP ではありません)

PHPStorm で PHP 関連の作業を行うために、Windows で WSL を設定しているところです。構成を開始し、Apache と PHP をインストールしました。確認のため、 でブラウザを開くとlocalhost動作しますが、 では127.0.0.1動作しません。

ポート転送を介して xdebug デバッグを構成できるようにするには、これを動作させる必要があります。私は localhost でこれを実行しようとしましたが失敗しました。docker で作業している他の (Linux) マシンでは簡単に実行できました。

私のUbuntuの中から:

~$ cat /etc/hosts

# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateHosts = false
127.0.0.1       localhost
127.0.1.1       JB-PC.localdomain       JB-PC

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

Windows の場合:

C:\WINDOWS\system32>ipconfig

Configuration IP de Windows


Carte Ethernet Ethernet :

   Suffixe DNS propre à la connexion. . . : Home
   Adresse IPv6 de liaison locale. . . . .: fe80::f04e:ae2b:40b9:3d82%6
   Adresse IPv4. . . . . . . . . . . . . .: 10.0.0.8
   Masque de sous-réseau. . . . . . . . . : 255.255.255.0
   Passerelle par défaut. . . . . . . . . : 10.0.0.138

Carte Ethernet vEthernet (WSL) :

   Suffixe DNS propre à la connexion. . . :
   Adresse IPv6 de liaison locale. . . . .: fe80::68c3:25c9:588a:a957%17
   Adresse IPv4. . . . . . . . . . . . . .: 172.20.32.1
   Masque de sous-réseau. . . . . . . . . : 255.255.240.0
   Passerelle par défaut. . . . . . . . . :

localhost::1 にピン留め:

C:\WINDOWS\system32>ping localhost

Envoi d’une requête 'ping' sur JB-PC [::1] avec 32 octets de données :
Réponse de ::1 : temps<1ms
Réponse de ::1 : temps<1ms
Réponse de ::1 : temps<1ms
Réponse de ::1 : temps<1ms

Statistiques Ping pour ::1:
    Paquets : envoyés = 4, reçus = 4, perdus = 0 (perte 0%),
Durée approximative des boucles en millisecondes :
    Minimum = 0ms, Maximum = 0ms, Moyenne = 0ms

そして127.0.0.1pingも同様です:

C:\WINDOWS\system32>ping 127.0.0.1

Envoi d’une requête 'Ping'  127.0.0.1 avec 32 octets de données :
Réponse de 127.0.0.1 : octets=32 temps<1ms TTL=128
Réponse de 127.0.0.1 : octets=32 temps<1ms TTL=128
Réponse de 127.0.0.1 : octets=32 temps<1ms TTL=128
Réponse de 127.0.0.1 : octets=32 temps<1ms TTL=128

Statistiques Ping pour 127.0.0.1:
    Paquets : envoyés = 4, reçus = 4, perdus = 0 (perte 0%),
Durée approximative des boucles en millisecondes :
    Minimum = 0ms, Maximum = 0ms, Moyenne = 0ms

また、私は答えを試してみましたここ、しかし彼らは助けにはなりませんでした。

[編集] @NotTheDr01ds の提案に従って、Python で試してみました。ポート 8080 の localhost または 127.0.0.1 にアクセスすると、すべて同じように動作しますが、http://0.0.0.0:8080/CLI ではそれが提供されていると表示されているにもかかわらず、奇妙なことにアクセスは動作しません。

C:\WINDOWS\system32>python3 -m http.server 8080 --bind 0.0.0.0
Serving HTTP on 0.0.0.0 port 8080 (http://0.0.0.0:8080/) ...
127.0.0.1 - - [17/Apr/2021 21:20:38] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [17/Apr/2021 21:20:39] code 404, message File not found
127.0.0.1 - - [17/Apr/2021 21:20:39] "GET /favicon.ico HTTP/1.1" 404 -
127.0.0.1 - - [17/Apr/2021 21:21:15] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [17/Apr/2021 21:21:15] code 404, message File not found
127.0.0.1 - - [17/Apr/2021 21:21:15] "GET /favicon.ico HTTP/1.1" 404 -

私の 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 www.example.com

        ServerName localhost
        ServerAdmin webmaster@localhost
        DocumentRoot /mnt/c/Users/JB/Documents/projects/bdzserver/public

        # 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

        <Directory /mnt/c/Users/JB/Documents/projects/bdzserver>
                Options Indexes FollowSymLinks
                AllowOverride All
                Require all granted
        </Directory>

        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>

関連情報