我正在 Windows 上设置 WSL,以便使用 PHPStorm 处理 PHP 内容。已开始配置,并安装了 Apache 和 PHP。为了检查,我在 上打开浏览器localhost
,它可以运行,但在 上127.0.0.1
却不行。
我需要它工作才能通过端口转发配置 xdebug 调试。我在 localhost 上做不到这一点,而我在另一台 (Linux) 机器上做这件事很轻松,因为我正在使用 docker。
从我的 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 上执行 ping 操作:
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.1
执行 ping 操作:
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。访问 localhost 或 127.0.0.1 端口 8080 都一样有效,但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>