LNMP: nginx solve connect() failed

Posted Jun 16, 20202 min read

problem

After installing the wsl subsystem under win10 and successfully setting up the lnmp environment, the 502 error appears in the ngixn request. Check the nginx log(/var/log/nginx/error.log) and report the error as follows.

2020/06/16 11:09:50 [error]2293#2293:*1 upstream timed out(110:Connection timed out) while reading upstream, client:192.168.58.102, server:192.168.xx.xx , request:"POST your request address HTTP/1.1", upstream:"fastcgi://unix:/run/php/php7.2-fpm.sock:", host:"192.168.xx.xx", referrer:"Your request address"

Location troubleshooting

Check if php-fpm is running

Execute the command to check the startup status of php-fpm, if not, start php-fpm

/etc/init.d/php7.2-fpm status

or

ps -ef|grep php

image.png

Is the php-fpm queue full

  1. Add a location in the nginx configuration, set as follows

    location ~ ^/status${

     include fastcgi_params;
     fastcgi_pass 127.0.0.1:9000;
     fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;

    }

  2. Open options in php-fpm.conf

    pm.status_path = /status

  3. After setting, you can see the current PHP status through http://domain name/status . Examples are as follows.

Confirm nginx configuration file

Because nginx and php have two connection methods.
Connection method 1:

fastcgi_pass 127.0.0.1:9000;

Connection method two:

fastcgi_pass unix:/run/php/php7.2-fpm.sock;

How to use this to go to php-fpm to see his configuration file
Listen configuration in /etc/php/7.2/fpm/pool.d/ www.conf .

If Listen is a port, write 127.0.0.1:9000;
If it is a path, the nginx configuration file should also be a path, unix:/run/php/php7.0-fpm.sock;

After confirming that the two addresses have been configured, restart nginx to access it.