Nginx - 502 Bad Gateway on Drupal 8

By xngo on April 17, 2021

Issue

For a long time, I heard that Nginx is much faster and uses far less memory than Apache. Well, today, I decide to take the plunge and replace Apache with Nginx.

I use the configuration for Drupal from https://www.nginx.com/resources/wiki/start/topics/recipes/drupal/. After setting up everything and open the website, I got 502 Bad Gateway error.

I checked the error log and it is showing the following.

2021/04/17 09:28:47 [crit] 8420#8420: *1 connect() to unix:/var/run/php/php7.0-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 127.0.0.1, server: spacbus-test, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.0-fpm.sock:", host: "spacbus-test"

Solution

It turned out that the my configuration file is pointing to the wrong FPM version. I changed fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; to fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;. Then, restart nginx.

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.