Nginx 502 Bad Gateway solution

0
262

If there is no Rule Iptable to open ports that serve scripts fcgi (fastcgi), then you will find the message “502 bad Gateway Nginx”. To open the cPanel will still appear error such as it is. General port for fcgi is 4567 and 9000, then open the ports in iptables. How to type the following command in SSH:

# iptables -I INPUT 1 -p tcp –dport 4567 -j ACCEPT

Solution Error nginx 502 Bad gateway problem because the socket, check the log URerror.log nginx/var/log/nginx and if there is a description of the connect () to unix:/var/run/php-fpm.socket failed to change the TCP/IP socket php-fpm way as below:

Bad Gateway

1. open the Virtualhost config Nginx

See at line fastcgi_pass

location ~ \.php?$ {
fastcgi_pass 127.0.0.1:9001;
}

2. change the TCP/IP Socket

to Change the TCP/IP connection into a unix socket as below:

location ~ \.php?$ {
fastcgi_pass unix:/var/run/php-fpm.socket;
}

3. Restart Nginx and PHP-FPM

# service nginx restart
# service php-fpm restart

and goodbye error 502 bad gateway nginx

experience, usually the first time install nginx forget, so I created a post who knows anyone experiencing similar problems and this is the solution to overcome the error 502 Bad gateway on nginx and php-fpm.

Note:
1. do not forget to check the logs of php-fpm is also the location of the php-fpm logging location is on/var/log/php-fpm/
2. check socket php-fpm. socket in/var/run

NO COMMENTS

LEAVE A REPLY