16

I don't know why I got this error every time I tried to open the page:

2013/04/06 17:52:19 [error] 5040#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "GET /info.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "localhost:8080"
1
  • 2
    It might help if you show the relevant parts of your configuration file(s).
    – chue x
    Apr 6, 2013 at 16:26

5 Answers 5

39

I resolved it, it was a configuration file issue, I added:

location ~ .php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
}
4
  • 4
    There are some situations when fastcgi_pass 127.0.0.1:9000; is present in server block and is responsible for this error, in such cases you need change it to fastcgi_pass unix:/var/run/php5-fpm.sock;.
    – xyz
    Dec 8, 2013 at 10:34
  • 2
    This is because php5-fpm now ships with the Unix socket listen = /var/run/php5-fpm.sock enabled in /etc/php5/fpm/pool.d/www.conf instead of the TCP socket listen = 127.0.0.1:9000. This is typically a little faster. (For google search purposes) ubuntu 14.04 nginx php5-fpm 502 Bad Gateway. I have a feeling a lot of people will be needing this in the near future. There are so many tutorials with the old socket in place.
    – DutGRIFF
    May 9, 2014 at 6:09
  • Thank you, @KamilZieliński! Changing to fastcgi_pass unix:/var/run/php5-fpm.sock; fixed my error.
    – Ryan
    Jun 4, 2014 at 18:31
  • In my case (centos 7) I had to use fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;. The error log is your friend:sudo tail -20 /var/log/nginx/error.log Feb 27, 2015 at 4:34
18

For me the problem was my php-fpm service wasn't running. You can check it by running:

service php-fpm status

and start it by running

service php-fpm start

Sometimes php-fpm might have broken instances running, preventing a restart. This command is a clean way to clear them out and restart php-fpm

killall -9 php-fpm; service php-fpm restart
1
  • for me restart of php-fpm and I need to do below : touch /var/run/php5-fpm.sock && chmod 777 /var/run/php5-fpm.sock Jul 9, 2015 at 11:54
3

update your configurations as mentioned before:

location ~ .php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}

but don't forget to restart both nginx server and php-fpm after updating

sudo /etc/init.d/nginx restart
sudo /etc/init.d/php-fpm restart
1
  • This belongs in a comment below the answer given. Kinda looks like you are just trying to get upvotes. Yes. Restarting nginx is necessary but most will know this and if they don't they will see it in a comment before they scroll all the way down here.
    – DutGRIFF
    May 9, 2014 at 2:44
3

I found I had this same issue with PHP7 running in Docker on a Debian Jessie (8.3) instance.

  • running command 'ps -aux' showed that php-fpm wasn't running
  • running 'php-fpm -D' brought it up as deamonized process.
  • Rerunning 'ps -aux' showed that php-fpm was indeed running
  • Refreshing my test page showed me the servers PHP info.

Added 'php-fpm -D' to my start.sh script so that things started every time the container is loaded.

Hope this helps someone.

0

Use fastcgi_pass unix:/var/run/php5-fpm.sock; only nginx and php install same server. If nginx and php install in other server you must use fastcgi_pass ip server:port;

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.