nginx连不上php导致502问题 connect() failed解决

报错日志

11 connect() failed (111: Connection refused) while connecting to upstream, client: 100.100.100.100, server: xxxxxx.com, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "xxxxxx.com"

conf配置不正确的问题:

    server {
        listen          80;
        server_name     yourdomain.com;
        root            /home/yourdomain/www/;
        index           index.html index.htm index.php;
 
        if (!-e $request_filename) {
            rewrite ^(.*)$ /index.php$1 last;
        }
 
        location ~ .*\.php(\/.*)*$ {
            include fastcgi.conf;
            fastcgi_pass  127.0.0.1:9000;
        }
 
        access_log logs/yourdomain.log combined;
    }

fastcgi_pass不能直接写127.0.0.1:9000

解决方法:

打开/etc/php/7.3/fpm/pool.d/www.conf文件
找到listen

listen = /run/php/php7.3-fpm.sock

配置改成:

    server {
        listen          80;
        server_name     yourdomain.com;
        root            /home/yourdomain/www/;
        index           index.html index.htm index.php;
 
        if (!-e $request_filename) {
            rewrite ^(.*)$ /index.php$1 last;
        }
 
        location ~ .*\.php(\/.*)*$ {
            include fastcgi.conf;
            #fastcgi_pass  127.0.0.1:9000;
             fastcgi_pass  unix:/run/php/php7.3-fpm.sock
        }
 
        access_log logs/yourdomain.log combined;
    }

评论

暂无

添加新评论