Question

502 Bad gateway when following LEMP install on new droplet

On a new droplet I have been working through the tutorial “How To Install Linux, Nginx, MySQL, PHP (LEMP stack) in Ubuntu 16.04” and am stuck with the php test failing with a 502 bad gateway. I have gone thru several times and can find no errors. Can anyone point me in the right direction?

Subscribe
Share

The file contents are correct but bell-computing.com/info.php generates the 501. Its in my document root /usr/share/nginx/html/info.php.

2016/08/08 18:03:11 [notice] 16407#16407: signal process started 2016/08/08 18:07:36 [crit] 16410#16410: *9 connect() to unix:/run/php/php7.0-fpm.sock failed (13: Permission denied) while connecting to upstream, client: 80.14.167.$ 2016/08/08 18:12:29 [crit] 16410#16410: *11 connect() to unix:/run/php/php7.0-fpm.sock failed (13: Permission denied) while connecting to upstream, client: 80.14.167$ 2016/08/08 18:19:52 [crit] 16410#16410: *16 connect() to unix:/run/php/php7.0-fpm.sock failed (13: Permission denied) while connecting to upstream, client: 80.14.167$ 2016/08/08 18:58:28 [crit] 16410#16410: *30 connect() to unix:/run/php/php7.0-fpm.sock failed (13: Permission denied) while connecting to upstream, client: 80.14.167$ 2016/08/08 20:54:21 [crit] 16410#16410: *44 connect() to unix:/run/php/php7.0-fpm.sock failed (13: Permission denied) while connecting to upstream, client: 80.14.167$

http://bell-computing.com/info.php generates 501. Here is the content of the sudo nano /usr/share/nginx/html/info.php <?php phpinfo(); ?>

and here is the output from sudo tail… 2016/08/08 17:58:47 [emerg] 16367#16367: directive “server_name” is not terminated by “;” in /etc/nginx/sites-enabled/default:43 2016/08/08 17:59:41 [emerg] 16371#16371: “fastcgi_pass” directive is duplicate in /etc/nginx/sites-enabled/default:60 2016/08/08 18:00:53 [emerg] 16375#16375: unexpected end of file, expecting “}” in /etc/nginx/sites-enabled/default:90 2016/08/08 18:01:42 [emerg] 16379#16379: unexpected end of file, expecting “}” in /etc/nginx/sites-enabled/default:90 2016/08/08 18:03:11 [notice] 16407#16407: signal process started 2016/08/08 18:07:36 [crit] 16410#16410: *9 connect() to unix:/run/php/php7.0-fpm.sock failed (13: Permission denied) while connecting to upstream, client: 80.14.167.$ 2016/08/08 18:12:29 [crit] 16410#16410: *11 connect() to unix:/run/php/php7.0-fpm.sock failed (13: Permission denied) while connecting to upstream, client: 80.14.167$ 2016/08/08 18:19:52 [crit] 16410#16410: *16 connect() to unix:/run/php/php7.0-fpm.sock failed (13: Permission denied) while connecting to upstream, client: 80.14.167$ 2016/08/08 18:58:28 [crit] 16410#16410: *30 connect() to unix:/run/php/php7.0-fpm.sock failed (13: Permission denied) while connecting to upstream, client: 80.14.167$

Hi!

In order to be able to better help you, we’ll need a bit more info first. Are there any errors in Nginx’s error logs (php errors should be forwarded to there too)?

sudo tail -30 /var/log/nginx/error.log

Though, to be honest, there’s not much that could go wrong with the basic info php file. Make sure that the function is spelled correctly without any underscores or hyphens: phpinfo();.


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

I got some ips blocking my sites, bad gateway error, seems they’re coming from Rusia, China and so on. I have to restart my fpm several times to have my apps up and running. is there any issue with fpm in droplets?

Edit the file /etc/php/7.0/fpm/pool.d/www.conf

And uncomment or add the following lines.

listen.owner = www-data
listen.group = www-data
listen.mode = 0660

If you are running Nginx as a different user, change www-data to that user. By default it will run as www-data.

You may have to delete the file /var/run/php/php7.0-fpm.sock if it exists.

Now run the commands below.

sudo service nginx restart
sudo service php7.0-fpm restart