nginx + php-fpm "connect() failed" errors in logs, no visible impact

Alec Sanger asked:

I’m trying to figure out why I have so many of these error logs:

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

All of the posts about this error that I’ve seen result in bad gateway errors, however I’ve quickly stepped through many pages on the site to try to get the error to pop up, and sure enough, the latest logs show this error with my IP. I never had any issue getting any pages to load, though. What could the issue be?

nginx config:

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;
        include sites-enabled/*.conf;

site-specific config:

server {
        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;

My answer:

You’ve specified two servers in your upstream block. When one fails, you get the error you are seeing in the logs, and then nginx tries the other one. Since this apparently connects successfully, you are not seeing user-visible errors such as 502 or 504.

I would guess that you converted your PHP-FPM setup from TCP connections to UNIX domain sockets, and forgot to remove the old server; line. If the errors bother you, then feel free to do so.

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.