WSL: Nginx w/ PHP-FPM 7.1 FastCGI w/ a Unix Socket hangs when fastcgi_buffering: on (default)
-
Windows build number: Microsoft Windows [Version 10.0.17134.285]
-
What I’m doing and what’s happening: Install PHP 7.1, follow normal Ubuntu guide on doing it. Create a test index.php with the contents:
<?php
phpinfo();
Visit localhost:80 or localhost:443
-
What’s wrong / what should be happening instead: Page loads half-way and hangs.
-
Current hack / workaround
Turn off fastcgi_buffering as per below:
location ~ \.php$ {
proxy_set_header X-Forwarded-Proto $scheme;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_buffering off; # This must be here for WSL as of 11/28/2018
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PHP_VALUE "upload_max_filesize = 20M \n post_max_size=21M";
include /etc/nginx/fastcgi.conf;
}
Not sure exactly what the issue is but it’s probably something to do with how WSL handles unix sockets.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 10
- Comments: 17
This is still an issue on 1909 (Build 18363.535)
workaround:
I’m using WSL1, php 7.4 and nginx. Had the same issue. I did what @amiletti did, it didn’t fix my issues…
However, adding these into my http block of nginx.conf fixed it. I don’t know much about nginx/configuration, but it solved my issue for local dev atleast
client_body_buffer_size seemed to be the main issue, but the others are safe-guards I guess.
WSL with:
same error on 2022/05/22.
work around with nginx config:
This is still an issue on
1903 (Build 18362.113)It seems wrong… but it works 😛
I had the same issue, when I print out a page, only the first part of the page is actually printed and the browser remains in loading state until nginx reaches timeout (I think).
I had this problem on a fresh installation of Ubuntu 20.04 on wsl 1 and PHP 7.4.
Based on Remi-Coulom advice and nginx documentation, I tried to increase fastcgi_buffer_size and fastcgi_buffers in “vhost” location PHP block and it seems to solve my problem.
I want to report that in my case fastcgi_buffering off doesn’t seem related to the problem. I hope this helps.
Great, thanks. I take it that last
epoll_wait()simply never returns. There have been fixes to somewhat similar issues in 1809, although I can’t pin your sequence on an exact dupe. See #3100 #2949 #2846 et al.Well luckily I encountered this while writing our dev on boarding guide for Windows so I can copy/paste the relevant parts.
Setup Ubuntu Environment in Windows
Install PHP for Ubuntu
sudo apt install software-properties-common- gets the add-apt-repository commandsudo add-apt-repository ppa:ondrej/phpsudo add-apt-repository ppa:ondrej/nginxsudo apt update- Updates your list of available packagessudo apt install php7.1 php7.1-bcmath php7.1-bz2 php7.1-cli php7.1-curl php7.1-dba php7.1-fpm php7.1-gd php7.1-mbstring php7.1-mcrypt php7.1-mysql php7.1-readline php7.1-soap php7.1-xml php7.1-zip php-gnupg php-pear php-memcached php-msgpack php-igbinary- Install PHP 7.1 and all extensions we absolutely needAt this point
php -vshould work from terminal and the ubuntu servicephp7.1-fpmshould be registered and started. It should already be listening on/run/php/php7.1-fpm.sock.Configure php-fpm
sudo nano /etc/php/7.1/fpm/php.inicgi.fix_pathinfo=0sudo service php7.1-fpm restartInstall Nginx
sudo apt install nginxsudo service nginx startEdit the default site:
sudo nano /etc/nginx/sites-available/defaultIn the server bracket add this:
sudo service nginx restartstrace
To gather this strace I lowered the nginx workers to 1 and attached to that one. Then I visited /info.php which was a page containing the phpinfo(); standard output.
During this time
/var/log/nginx/error.logrecorded this: