WSL2 上的 nginx 在几次请求后需要几分钟才能加载页面

nginx on WSL2 takes minutes to load the page after few requests

我确实阅读并尝试了以下内容;

但是 none 篇论文解决了这个问题。

问题
来自 Windows;当我通过 http://myproject.testhttps://myproject.test127.0.0.1 浏览位于 WSL2 的网站时,前 2-3 个请求速度很快(<100 毫秒)。然后下一个请求在没有被阻塞的情况下正好需要 60000 毫秒(1 分钟)才能收到。

配置 Windows 10

WSL 2 上的配置

项目

/etc/nginx/sites-available/myproject.test

server {
    listen 80;
    listen [::]:80;
    listen 443 ssl;
    listen [::]:443 ssl;

    ssl_certificate /home/clement/projects/certs/myproject.test.pem;
    ssl_certificate_key /home/clement/projects/certs/myproject.test-key.pem;

    client_max_body_size 108M;

    access_log /var/log/nginx/application.access.log;

    server_name myproject.test;
    root /home/clement/projects/myproject/public;
    index index.php;

    if (!-e $request_filename) {
        rewrite ^.*$ /index.php last;
    }

    location ~ \.php$ {
        fastcgi_buffering off;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PHP_VALUE "error_log=/var/log/nginx/application_php_errors.log";
        include fastcgi_params;
    }

}

我在使用 fastcgi_pass 127.0.0.1:9000;fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;

时遇到同样的问题

当我在项目中执行 php -S localhost:8080php artisan serve 时,一切正常。

用日志编辑
这是我在 nginx 上获得的日志,但即使有了这些信息,我仍然找不到解决问题的任何资源。

2020/08/07 23:06:30 [error] 1987#1987: *6 upstream timed out (110: Connection timed out) while reading upstream, client: 127.0.0.1, server: myproject.test, request: "GET /_debugbar/assets/javascript?v=1588748787 HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.4-fpm.sock:", host: "myproject.test", referrer: "http://myproject.test/"

或使用IP

2020/08/08 01:43:01 [error] 4080#4080: *4 upstream timed out (110: Connection timed out) while reading upstream, client: 127.0.0.1, server: myproject.test, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "myproject.test"

我终于找到问题了。尽管我按照说明安装了 WSL 2,但它使用的是 WSL 1。

powershell我运行 wsl -l -v 得到了结果

|---------------------|------------------|------------------|
|         NAME        |       STATE      |      VERSION     |
|---------------------|------------------|------------------|
|    Ubuntu-20.04     |      Stopped     |         1        |
|---------------------|------------------|------------------|

updating the kernel 之后,我可以使用命令将版本更改为 2 wsl --set-version Ubuntu-20.04 2

现在一切正常