WordPress.org

Ready to get started?Download WordPress

Forums

502 error caused by connection refused: (upstream fastcgi, etc) (23 posts)

  1. uglyelf
    Member
    Posted 2 years ago #

    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!!

  2. uglyelf
    Member
    Posted 2 years ago #

    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.

  3. Pothi
    Member
    Posted 2 years ago #

    *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).

  4. uglyelf
    Member
    Posted 2 years ago #

    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!

  5. uglyelf
    Member
    Posted 2 years ago #

    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. :-(

  6. Pothi
    Member
    Posted 2 years ago #

    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

  7. uglyelf
    Member
    Posted 2 years ago #

    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

  8. Pothi
    Member
    Posted 2 years ago #

    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

  9. uglyelf
    Member
    Posted 2 years ago #

    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.

  10. Pothi
    Member
    Posted 2 years ago #

    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.

  11. uglyelf
    Member
    Posted 2 years ago #

    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.

  12. Pothi
    Member
    Posted 2 years ago #

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

    chdir = /

    Did you try removing it and restarting php5-fpm?

  13. uglyelf
    Member
    Posted 2 years ago #

    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.

  14. Pothi
    Member
    Posted 2 years ago #

    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?

  15. uglyelf
    Member
    Posted 2 years ago #

    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.

  16. Pothi
    Member
    Posted 2 years ago #

    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?

  17. uglyelf
    Member
    Posted 2 years ago #

    Well we have figured out something. When nginx wasn't returning from a restart, what I called hanging, I could still reach mysite.com/readme.html, so nginx was up, and maybe just stuck waiting for fpm to return? Of course then it wasn't actually shutting down so when I tried to restart the server it would return without problems from stopping, but still say a server was running when I started it again.

    That said, I don't know how to connect to it over telnet

    from the server, "telnet 127.0.0.1:9000" just returns with connection refused.

  18. Pothi
    Member
    Posted 2 years ago #

    When nginx wasn't returning from a restart, what I called hanging, I could still reach mysite.com/readme.html, so nginx was up, and maybe just stuck waiting for fpm to return?

    No, nginx doesn't care about fpm. Nginx may not have been closed when you type sudo service nginx stop. That's why it can not start another instance of nginx and it just hangs. I may be wrong. You can check this by typing ps aux | grep nginx or pgrep nginx, just after issuing sudo service nginx stop. If nginx still runs, then the previous command did not work and the next command (sudo service nginx start) hangs up the server. That's why, when you reboot the server, nginx still restarts.

    Additional questions to troubleshoot further -

    - As you can not connect via telnet, can you please double check if fpm is still listening *only* to a port (I remember you mentioned you tried both socket and port. You may have forgotten to switch to port or enabled both. Just my guess. Sorry about asking this, if fpm is already listening to a port.)

    - Can you please double check at /var/lock/ (or whatever the directory) to see, if the socket for php-fpm is *not* there (as I've been assuming, fpm is set to listen to a port).

    - Did you check if the content of fastcgi_params file is correct?

    - Does your server have updated packages (especially php5-fpm)? If not, you may want to do sudo apt-get update && sudo apt-get upgrade. It could be a bug with php5-fpm (as nothing reaches php5-fpm and the connection is currently being closed before reaching)

  19. uglyelf
    Member
    Posted 2 years ago #

    I'm still using the fastcgi_params file you posted, as well as the php-fpm.conf.

    Just after stopping nginx, sudo service nginx stop returns: <myserver> 3635 0.0 0.2 6080 660 pts/1 S+ 18:30 0:00 grep --color=auto nginx so I think that means it is still running and not shutting down properly. I wish there was something in the error log.

    I know I found it on google before, but I can't refigure out how to check if fpm is listening over a port. Not feeling very smart right now.

    It's OK to ask about the port vs socket. I'm just trying the port. There is nothing in the socket.

    Yup. Everything is super updated. Just ran update and upgrade again, 0 changes.

  20. Pothi
    Member
    Posted 2 years ago #

    I can't refigure out how to check if fpm is listening over a port.

    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)

    <myserver> 3635 0.0 0.2 6080 660 pts/1 S+ 18:30 0:00 grep --color=auto nginx

    It actually means that nginx has stopped. So, starting Nginx seems to be an issue in your server.

    But, I don't see any further ideas to troubleshoot. Someone else might help you in this regard.

  21. ashleykza
    Member
    Posted 2 years ago #

    I was experiencing a similar issue and the problem was in the following file:

    /etc/php5/fpm/pool.d/www.conf

    I had the following line:

    listen = /tmp/php5-fpm.sock

    Which I changed as follows:

    listen = 9000

    And that fixed the problem for me. Might work for you too.

  22. uglyelf
    Member
    Posted 2 years ago #

    Thanks for trying Ashleykza. I'd already tried that. My nginx conf and http://www.conf match for their listening ports. :-(

    Believe me, I'm up for trying anything at this point. So keep the suggestions coming. ;-)

  23. kmalte
    Member
    Posted 1 year ago #

    Did you ever get this solved? I'm having the same problem when load is high. Seems to me that the issue is unclosed file handles (if using sock-file) or some connection limit (using tcpip).

Topic Closed

This topic has been closed to new replies.

About this Topic