我安装了 wsl2 => 然后 ubuntu => 然后 nginx => php.fpm(我需要的版本)
然后将 mysite.local.conf
添加到我的 nginx 配置中,但无法从 windows 访问 wsl 上的站点
nginx 配置代码:
server {
listen 80 default_server;
server_name mysite.local *.mysite.local;
root /mnt/d/projects/arash/original/Web/frontend/web;
access_log /mnt/d/projects/arash/original/logs/arash-access.log;
error_log /mnt/d/projects/arash/original/logs/arash-error.log;
location ~* ^/backend$ {
rewrite ^ http://backend.mysite.local permanent; #301 redirect
}
location ~* ^/setting$ {
rewrite ^ http://setting.mysite.local permanent; #301 redirect
}
if ($host ~* ^(arash\.local)) {
rewrite ^ http://www.$host$uri permanent; #301 redirect
}
location ~ /\. {
deny all;
}
location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
fastcgi_read_timeout 1h;
fastcgi_pass unix:/run/php/php7.1-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~* ^.+\.(rss|atom|jpg|jpeg|gif|png|ico|rtf|js|css|svg|woff)$ {
expires 7d;
}
charset utf8;
}
server {
listen 80;
server_name backend.mysite.local;
access_log /mnt/d/projects/arash/original/logs/arash-access.log;
error_log /mnt/d/projects/arash/original/logs/arash-error.log;
root /mnt/d/projects/arash/original/Web/backend;
location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
fastcgi_read_timeout 1h;
fastcgi_pass unix:/run/php/php7.1-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
server {
listen 80;
server_name setting.mysite.local;
access_log /mnt/d/projects/arash/original/logs/arash-access.log;
error_log /mnt/d/projects/arash/original/logs/arash-error.log;
root /mnt/d/projects/arash/original/Web/setting/web;
location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
fastcgi_read_timeout 1h;
fastcgi_pass unix:/run/php/php7.1-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
然后运行ln -s /etc/nginx/sites-available/mysite.local.conf /etc/nginx/sites-enabled/
然后使用 ifconfig 172.28.11.207
获取我的 wsl IP 并将 172.28.11.207 mysite.local
添加到 Windows 主机然后尝试从 Windows 浏览器访问 mysite.local
什么也没显示
我也设置了 127.0.0.1 mysite.local
但也没机会
每次更改主机后我都使用了 ipconfig /flushdns
windows 快速启动的配置是关闭的 windows上hibernate的配置是关闭的
然后我尝试了 https://docs.microsoft.com/en-us/windows/wsl/wsl-config#wsl-2-settings 并使用以下代码向我的用户添加了 .wslconfig:
[wsl2]
localhostForwarding=true
什么都没有
当我尝试运行 curl mysite.local
时,我得到了 curl: (7) Failed to connect to mysite.local port 80: Connection refused
然后我将 wsl 设置为使用带有 wsl --set-version Ubuntu-20.04 1
的版本 1 并再次运行 curl mysite.local
现在我得到 curl: (52) Empty reply from server