在Ubuntu Windows子系统Linux上PHP7.0-fpm非常慢

问题描述 投票:11回答:2

我最近安装了Windows Subsystem Ubuntu shell,并将我的所有开发从XAMPP转移到通过ubuntu windows子系统安装的nginx和php7.0-fpm。

我面临的问题是php文件加载速度极慢。对于测试我简单地说

<?php phpinfo(); ?>

在一个文件中并执行它。字面上,系统花了两分钟才回复。我调试了很多,但找不到任何解决方案。

我通过nginx服务器块运行nginx并设置了我的本地域。

我确信通过观察如果我加载一个静态文件,即txt或html文件,它会加载速度非常快。

下面是我的网站启用文件和nginx conf文件..

网站已启用

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

    root /mnt/c/xampp/htdocs/doit/;
    index index.html index.php;

    server_name doit.dev www.doit.dev;
    error_log /var/log/nginx/error.log;
    location / {
        try_files $uri $uri/ =404;
    }
    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_read_timeout 120;
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    location ~ /\.ht {
        deny all;
    }   
}

Nginx配置文件:

user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}


#mail {
#   # See sample authentication script at:
#   # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
# 
#   # auth_http localhost/auth.php;
#   # pop3_capabilities "TOP" "USER";
#   # imap_capabilities "IMAP4rev1" "UIDPLUS";
# 
#   server {
#       listen     localhost:110;
#       protocol   pop3;
#       proxy      on;
#   }
# 
#   server {
#       listen     localhost:143;
#       protocol   imap;
#       proxy      on;
#   }
#}

nginx和php-fpm工作的错误日志,没有记录任何错误。

nginx fastcgi php-7
2个回答
22
投票

通过WSL使用Windows 10 v1803和nginx和php7 fpm。

更改听取127.0.0.1:9000对我不起作用。

花了几个小时的谷歌搜索后,我发现:https://github.com/Microsoft/WSL/issues/2100

即添加

fastcgi_buffering off;

到nginx.conf,并保存我的一天。


21
投票

对此进行排序,粘贴在Windows子系统上使用ubuntu的任何其他发烧友。

默认的Nginx和php设置将使用unix:socket,但这对WSL不起作用。此外,WSL使用轻量级的init系统,并且服务不会自动为Nginx,PHP,MySQL等启动。


编辑/etc/nginx/sites-available/example.com.conf

评论fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;

并添加fastcgi_pass 127.0.0.1:9000;


编辑/etc/php/7.0/fpm/pool.d/www.conf

评论listen = /var/run/php/php7.0-fpm.sock;

并添加listen = 127.0.0.1:9000;


它将解决您的所有问题。

© www.soinside.com 2019 - 2024. All rights reserved.