Nginx 502 Error with iRedMail and CentOS 7

Page Header

Installing iRedMail is quite a simple process with the provided installation script, but I found with CentOS installations with the GUI enabled the web server would throw 502 errors.

After some tinkering and googling, I’ve come up with a solution to the problem.

The problem specifically? I was getting this in my nginx error log (/var/log/nginx/error.log):

1
2015/10/19 22:28:44 [crit] 25668#0: *2 connect() to unix:/var/run/php-fpm/php-fpm.socket failed (2: No such file or directory) while connecting to upstream, client: 192.168.1.2, server: _, request: "GET /mail/ HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.socket:", host: "example.com"

Now apparently this means that there is a permissions problem with nginx communicating to php-fpm. I’m not going to lie, I really have no clue what this means, but here’s what I did to fix it:

1
2
3
4
5
## Make php-fpm listen on port 9000
sed -i 's\listen = /var/run/php-fpm/php-fpm.socket\listen = 127.0.0.1:9000;\g' /etc/php-fpm.d/www.conf

## Tell nginx to connect to it over the network instead
sed -i 's/fastcgi_pass php_workers;/fastcgi_pass 127.0.0.1:9000;/g' /etc/nginx/conf.d/default.conf

Now because this failed during the initial installation, the services required won’t have started, so start them all up:

1
2
3
4
5
systemctl restart uwsgi
systemctl restart php-fpm
systemctl restart nginx
systemctl restart dovecot
systemctl restart iredapd

I hope this works for you as it did for me.