【问题标题】:nginx on WSL2 takes minutes to load the page after few requests几次请求后,WSL2 上的 nginx 需要几分钟才能加载页面
【发布时间】:2020-08-07 15:23:25
【问题描述】:

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

但这些都没有解决问题。

问题
从 Windows;当我通过http://myproject.testhttps://myproject.test127.0.0.1 浏览位于 WSL2 的网站时,前 2-3 个请求正在快速进行(

Windows 10 上的配置

  • 防火墙已禁用
  • 127.0.0.1 myproject.test 添加到 C:\Windows\System32\drivers\etc\hosts
  • mkcerts 已安装
  • 安装了 Ubuntu 20.04 的 WSL 2

WSL 2 上的配置

  • Ubuntu 20.04
  • nginx 1.18
  • mysql 8.0
  • php-fpm 7.4

项目

  • Laravel
  • 位置/home/clement/projects/myproject/
  • 证书(使用 mkcert 生成)/home/clement/projects/certs/
  • 所有者:clement:www-data
  • 权限:777(仅用于测试和开发目的)

/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 [错误] 1987#1987: *6 上游超时(110:连接超时),同时读取上游,客户端:127.0.0.1,服务器:myproject.test,请求: “GET /_debugbar/assets/javascript?v=1588748787 HTTP/1.1”,上游:“fastcgi://unix:/run/php/php7.4-fpm.sock:”,主机:“myproject.test”,推荐人: "http://myproject.test/"

或者使用IP

2020/08/08 01:43:01 [错误] 4080#4080: *4 上游超时(110:连接超时),同时读取上游,客户端:127.0.0.1,服务器:myproject.test,请求: “GET / HTTP/1.1”,上游:“fastcgi://127.0.0.1:9000”,主机:“myproject.test”

【问题讨论】:

    标签: nginx windows-subsystem-for-linux wsl-2


    【解决方案1】:

    我终于找到了问题。尽管我按照说明安装了 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

    现在一切正常

    【讨论】:

      猜你喜欢
      • 2021-09-09
      • 2016-01-18
      • 2017-05-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多