92

Trying to deploy my first portal .

I am getting 502 gateway timeout error in browser when i was sending the request through browser

when i checked the logs , i got this error

 2014/02/03 09:00:32 [error] 16607#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 14.159.131.19, server: foo.com, request: "GET HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "22.11.180.154"

is there any problem related to permissions

Paulo Boaventura
  • 1,365
  • 1
  • 9
  • 29
Abhishek Tripathi
  • 1,570
  • 3
  • 20
  • 32

4 Answers4

105

I don't think that solution would work anyways because you will see some error message in your error log file.

The solution was a lot easier than what I thought.

simply, open the following path to your php5-fpm

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

or if you're the admin 'root'

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

Then find this line and uncomment it:

listen.allowed_clients = 127.0.0.1

This solution will make you be able to use listen = 127.0.0.1:9000 in your vhost blocks

like this: fastcgi_pass 127.0.0.1:9000;

after you make the modifications, all you need is to restart or reload both Nginx and Php5-fpm

Php5-fpm

sudo service php5-fpm restart

or

sudo service php5-fpm reload

Nginx

sudo service nginx restart

or

sudo service nginx reload

From the comments:

Also comment

;listen = /var/run/php5-fpm.sock 

and add

listen = 9000
ewwink
  • 18,382
  • 2
  • 44
  • 54
Digital site
  • 4,431
  • 12
  • 48
  • 72
  • 31
    `listen = 9000` and `;listen = /var/run/php5-fpm.sock` – n611x007 Jan 01 '15 at 16:16
  • 1
    On CentOS 7 this file was at `/etc/php-fpm.d/www.conf` for me and I had to add `listen = 9000` and comment out `listen = /var/run/php-fpm/php-fpm.sock`. – junkie Oct 23 '16 at 21:36
  • 2
    Why not change the NGINX config to use sockets instead of localhost:9000? By changing the `fastcgi_pass` line to "`astcgi_pass unix:/run/php/php7.0-fpm.sock;` – KNejad Dec 09 '19 at 14:07
1

I had the same problem when I wrote two upstreams in NGINX conf

upstream php_upstream {
    server unix:/var/run/php/my.site.sock;
    server 127.0.0.1:9000;
}

...

fastcgi_pass php_upstream;

but in /etc/php/7.3/fpm/pool.d/www.conf I listened the socket only

listen = /var/run/php/my.site.sock

So I need just socket, no any 127.0.0.1:9000, and I just removed IP+port upstream

upstream php_upstream {
    server unix:/var/run/php/my.site.sock;
}

This could be rewritten without an upstream

fastcgi_pass unix:/var/run/php/my.site.sock;
and1er
  • 749
  • 8
  • 18
0

This may be useful for someone:

If you have multiple versions of PHP installed e.g 8.0 and 7.4 on your mac, and you have tried several options and still gets a 502 Gateway error, trying check how your valet connects with your PHP version and Nginx.

from terminal run valet use php@7.4 if that's the version you use. The current version will be unlinked and the new version linked then Nginx and php@7.4 will be restarted.

23b
  • 58
  • 5
Lekia
  • 105
  • 1
  • 12
0

I faced the same issue in Centos 8. In this file /etc/nginx/default.d/php.conf I just replaced the below line, and it works perfectly.

#orignal line
fastcgi_pass 127.0.0.1:9000;

#replaced with
fastcgi_pass unix:/run/php-fpm/www.sock;
Niyaz
  • 797
  • 1
  • 8
  • 18