nginx + php-fpm 日志中出现“connect() failed”错误,无明显影响

nginx + php-fpm 日志中出现“connect() failed”错误,无明显影响

我试图弄清楚为什么我有这么多这样的错误日志:

[error] 1545#0: *713626 connect() failed (111: Connection refused) while connecting to upstream, client: xx.xx.xx.xx, server: www.example.com, request: "GET / HTTP/1.0", upstream: "fastcgi://127.0.0.1:9000", host: "www.example.com"

我见过的所有关于此错误的帖子都会导致网关错误,但是我快速浏览了网站上的许多页面,试图弹出错误,果然,最新日志显示我的 IP 出现了此错误。但我从未遇到过加载任何页面的问题。问题可能是什么?

nginx配置:

worker_processes  1;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    # output compression saves bandwidth
    gzip  on;
    gzip_static on;
    gzip_http_version 1.1;
    gzip_vary on;
    gzip_min_length 1400;
    gzip_comp_level 9;
    gzip_proxied any;
    gzip_types text/plain text/css application/json application/javascript application/x-javascript text/javascript text/xml application/xml application/rss+xml application/atom+xml application/rdf+xml image/png image/gif image/jpeg image/jpg;

    gzip_buffers 16 8k;

    # Disable gzip for certain browsers.
    gzip_disable âMSIE [1-6].(?!.*SV1)â

     server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

 upstream php {
         server unix:/var/run/php-fpm/php-fpm.sock;
                 server 127.0.0.1:9000;
                 }
        include sites-enabled/*.conf;
}

站点特定配置:

server {
        server_name www.example.com;
        root /blah/blah/blah;
        index index.php;

        include global/restrictions.conf;
        include global/wordpress.conf;

        location ~ \.php$ {
                include fastcgi.conf;
                fastcgi_intercept_errors on;
                fastcgi_pass php;
        }

        location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
                expires max;
                add_header Pragma public;
                add_header Cache-Control "public, must-revalidate, proxy-revalidate";
                log_not_found off;
        }
}

答案1

server您在块中指定了两个upstream。当其中一个失败时,您会收到日志中看到的错误,然后 nginx 会尝试另一个。由于这显然连接成功,因此您不会看到用户可见的错误,例如 502 或 504。

我猜想您已将 PHP-FPM 设置从 TCP 连接转换为 UNIX 域套接字,但忘记删除旧server 127.0.0.1:9000;行。如果这些错误让您感到困扰,请随意删除。

相关内容