Support » Fixing WordPress » 502 error caused by connection refused: (upstream fastcgi, etc)

  • Hi.

    I’ve been trying to upgrade my server from a single-site to a multi-site (eventually with distinct domains). I followed the directions from the codex:
    http://codex.wordpress.org/Nginx

    Which use php5-fpm. I installed fpm, but something is going wrong and it doesn’t seem to be running no matter that I restart it.

    The error in /var/log/nginx/error.log is:

    2012/06/20 21:28:30 [error] 3391#0: *21 connect() failed (111: Connection refused) while connecting to upstream, client: <my home ip>, server: *.<mysite>.com, request: "GET /tag/pdx/ HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.<mysite>.com"

    My nginx.conf includes:

    # Upstream to abstract backend connection(s) for PHP.
            upstream php {
    #               server unix:/tmp/php-fpm.sock;
                    server 127.0.0.1:9000;
            }

    and my /etc/php5/fpm/pool.d/www.conf includes:

    listen = 127.0.0.1:9000
    ;listen = /tmp/php-fpm.sock

    I have also tried commenting out the port options and uncommenting the socket options and restarting the nginx and php-fpm servers, to the same effect (with the relevant change to the error message.

    Now here’s where it get’s funky.
    using the command: sudo netstat -tlpn | grep :9000 (found after much googling)
    Shows:
    tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 3454/php-fpm.conf)
    Which implies to me that fpm is alive and listening. Any ideas?? I’ve been working on this for a week!!

Viewing 15 replies - 1 through 15 (of 22 total)
  • Anyone? Anything? The PHP logs only show that FPM is up and listening. I’m thinking of uninstalling and re-installing anything with PHP in the name, not so much because I think that will fix anything but because I am out of things to try. 🙁

    Any next steps would be appreciated.

    *21 connect() failed (111: Connection refused)

    It probably means there is an issue with permissions.

    Who is the owner (and/or group) in your “/etc/php5/fpm/pool.d/www.conf”?

    Does “that person” have read/write privilege in /path/to/wordpress/files ?

    Hope this helps. (if it doesn’t, please post your entire Nginx configuration via pastebin).

    In http://www.conf:

    ; Unix user/group of processes
    ; Note: The user is mandatory. If the group is not set, the default user's group
    ;       will be used.
    user = www-data
    group = www-data

    User configured in nginx.conf: user www-data www-data;

    www-data didn’t have read/write to my blog files. So I chgrp’d the public folder. After www-data had access to the entire blog structure there was still no change. My nginx conf is:
    http://pastebin.com/z34N7qgR

    Thank you trying to help!

    If this helps at all, when if I start nginx after the server is running rather than on boot, it hangs. There is nothing in the nginx error logs. Is there another log where I might look for a problem?

    I have changed ownership of the web site folders to be www-data, so that shouldn’t be a conflict.

    I’m still struggling here. 🙁

    I’m sorry to hear you still have some issues with nginx and php-fpm.

    Please let me divide the current issues and what works and what doesn’t.

    I’ve been trying to upgrade my server from a single-site to a multi-site (eventually with distinct domains)

    Did nginx and php-fpm work fine with a single-site install?

    My nginx conf is: http://pastebin.com/z34N7qgR

    Please post your entire Nginx configuration via pastebin including the vhost configuration. It would also help if you post your /etc/php5/fpm/pool.d/www.conf. Of course, you may remove anything that you wouldn’t want to share in public (such as the domain name).

    if I start nginx after the server is running rather than on boot, it hangs. There is nothing in the nginx error logs. Is there another log where I might look for a problem?

    This is strange. I never came across this issue earlier. So, not sure how to troubleshoot this.

    BTW, which OS are you running and how did you install nginx (from RPM package or from source)?

    Sorry about asking too many questions. You may ignore certain questions, if inappropriate.

    Thanks,
    Pothi

    Pothi, Thank you for your help!

    In order:

    Did nginx and php-fpm work fine with a single-site install?

    Previously I wasn’t using FPM. The single site still works fine with the old configuration files, but there’s no FPM involved.

    vhost: http://pastebin.com/1chCsTQz
    restrictions: http://pastebin.com/KGjSEkPK
    global conf: http://pastebin.com/V57tvwvP

    However, it’s worth noting that the server hangs even when there is no link in the sites-enabled directory. In other words, the server hangs even without a vhost.

    http://www.conf: http://pastebin.com/W72KHaW1 (I removed all comments for brevity)

    The server is on rackspace (formerly slice host) and it’s a VPS running ubuntu 10.04;

    I don’t mind the questions. I have no idea how to continue trouble shooting this. I’m really just glad you’re trying to help.

    Thank you!
    -gregory

    Okay, thanks for providing additional details.

    Regarding permissions:

    I have changed ownership of the web site folders to be www-data

    I understand you setup read/write permissions at /home/mysite/public_html/<mysite>.com/public/ for user www-data. But, does that user (www-data) have read permission at the following locations?

    /home/
    /home/mysite/
    /home/mysite/public_html/
    /home/mysite/public_html/<mysite>.com/

    Regarding the server hanging:

    Can you please share what happens when you try the following? (assuming you installed Nginx from the repo provided by Ubuntu or Nginx)

    nginx -t
    nginx -t && service nginx reload
    service nginx stop
    service nginx start
    nginx -t && service nginx restart

    Thanks,
    Pothi

    Read permission, yes. But not write permission. I can’t see why www-data would need to write to those places.

    I did install nginx from the repo. Here is what I get:
    /etc/nginx: sudo /usr/sbin/nginx -t
    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /etc/nginx/nginx.conf test is successful

    /etc/nginx: sudo /usr/sbin/nginx -t && sudo service nginx reload
    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /etc/nginx/nginx.conf test is successful
    Reloading nginx configuration: nginx.

    sudo service nginx stop
    Stopping nginx: nginx.

    sudo service nginx start
    Starting nginx:
    And here it hangs. It does not return, so I didn’t try the last command.

    Okay, thanks for the additional details.

    Can you access yoursite.com/readme.html without any errors? (just wanted to make sure, if static files are served correctly)

    As Nginx reloading works, you may stick with nginx -t && service nginx reload whenever you modify the configuration. It is not necessary to restart Nginx, as you may already aware.

    Yes. I can access mysite.com/readme.html; so that’s working. Still “502 Bad Gateway” for mysite.com.

    Again. Thanks for all your help.

    I noticed that there is a line (line # 19) in your www.conf file…

    chdir = /

    Did you try removing it and restarting php5-fpm?

    That was a default setting (not something I configured) but I removed it anyway. No change after restarting php5-fpm and nginx. I thought we were onto something there.

    Can you please try a single site configuration with a far-simpler settings?

    Here is my nginx vhost configuration, the contents of fastcgi_params and my php-fpm.conf.

    If it still doesn’t work, does /path/to/xxx-error.log (as mentioned in my php-fpm.conf file) it give any clues?

    I tried it and pointed the logs to /var/log/nginx/xxx-error.log and /var/log/nginx/xxx-slow.log. (yes, I know it’s php logs, but it was a convenient place to set them for now) I restarted the servers and browsed to it, but it didn’t actually create the error logs. So I rebooted. Still didn’t create the logs.

    I did change user and group from xxx to the user and group I’ve been using. I assumed I should

    That’s just weird.

    Yeh, weird issues that I haven’t seen earlier (nginx hanging, php5-fpm not connecting). Can you connect to php5-fpm using telnet 127.0.0.1 9000?

Viewing 15 replies - 1 through 15 (of 22 total)
  • The topic ‘502 error caused by connection refused: (upstream fastcgi, etc)’ is closed to new replies.