1

Topic: 502 Bad Gateway - nginx

==== REQUIRED BASIC INFO OF YOUR IREDMAIL SERVER ====
- iRedMail version (check /etc/iredmail-release): 1.6.3 MARIADB edition
- Deployed with iRedMail Easy or the downloadable installer? downloadable installer
- Linux/BSD distribution name and version: Ubuntu 20.04.6 LTS
- Store mail accounts in which backend (LDAP/MySQL/PGSQL): MySQL
- Web server (Apache or Nginx): Nginx
- Manage mail accounts with iRedAdmin-Pro? Yes
- [IMPORTANT] Related original log or error message is required if you're experiencing an issue.
====

Hi there

We have been experiencing issues with Roundcube Webmail and Nginx since we upgraded Roundcube to 1.6.1.

Roundcube is super slow, takes a long time to load messages and sometimes shows a 502 Bad Gateway.

Initially, I thought it could be a big with the newly installed Roundcube Webmail 1.6.1, so I upgraded it to Roundcube Webmail 1.6.2. But that did not help.

This is what I see in /var/log/nginx/error.log when a 502 Bad Gateway occurs:

2023/07/24 19:36:13 [error] 967#967: *76628 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 85.240.81.200, server: webmail.grupow.com.br, request: "GET /?_task=mail&_mbox=INBOX HTTP/2.0", upstream: "fastcgi://127.0.0.1:9999", host: "webmail.grupow.com.br", referrer: "https://webmail.grupow.com.br/"
2023/07/24 19:36:13 [error] 967#967: *73287 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 201.131.138.33, server: webmail.grupow.com.br, request: "POST /?_task=mail&_action=refresh HTTP/2.0", upstream: "fastcgi://127.0.0.1:9999", host: "webmail.grupow.com.br", referrer: "https://webmail.grupow.com.br/"
2023/07/24 19:37:37 [error] 967#967: *77291 open() "/var/www/html/owa/auth/logon.aspx" failed (2: No such file or directory), client: 107.170.228.11, server: _, request: "GET /owa/auth/logon.aspx?url=https%3a%2f%2f1%2fecp%2f HTTP/1.1", host: "186.250.184.217"
2023/07/24 19:37:46 [error] 967#967: *77298 open() "/var/www/html/owa/auth/logon.aspx" failed (2: No such file or directory), client:

This is what I see in /var/log/php-fpm/slow.log

[24-Jul-2023 19:36:23]  [pool inet] pid 450629
script_filename = /opt/www/roundcubemail/index.php
[0x00007f55aa813d50] fgets() /opt/www/roundcubemail/program/lib/Roundcube/rcube_imap_generic.php:212
[0x00007f55aa813cb0] readLine() /opt/www/roundcubemail/program/lib/Roundcube/rcube_imap_generic.php:332
[0x00007f55aa813bc0] readReply() /opt/www/roundcubemail/program/lib/Roundcube/rcube_imap_generic.php:780
[0x00007f55aa813a30] authenticate() /opt/www/roundcubemail/program/lib/Roundcube/rcube_imap_generic.php:991
[0x00007f55aa813930] connect() /opt/www/roundcubemail/program/lib/Roundcube/rcube_imap.php:172
[0x00007f55aa813800] connect() /opt/www/roundcubemail/program/lib/Roundcube/rcube_imap.php:248
[0x00007f55aa813790] check_connection() /opt/www/roundcubemail/program/lib/Roundcube/rcube_imap.php:2955
[0x00007f55aa813650] list_folders_subscribed_direct() /opt/www/roundcubemail/program/lib/Roundcube/rcube_imap.php:2914
[0x00007f55aa813570] list_folders_subscribed() /opt/www/roundcubemail/program/actions/mail/check_recent.php:53
[0x00007f55aa813300] run() /opt/www/roundcubemail/program/include/rcmail.php:282
[0x00007f55aa8131d0] action_handler() /opt/www/roundcubemail/index.php:278

[24-Jul-2023 19:36:59]  [pool inet] pid 452975
script_filename = /opt/www/roundcubemail/index.php
[0x00007f55aa813d50] fgets() /opt/www/roundcubemail/program/lib/Roundcube/rcube_imap_generic.php:212
[0x00007f55aa813cb0] readLine() /opt/www/roundcubemail/program/lib/Roundcube/rcube_imap_generic.php:332
[0x00007f55aa813bc0] readReply() /opt/www/roundcubemail/program/lib/Roundcube/rcube_imap_generic.php:780
[0x00007f55aa813a30] authenticate() /opt/www/roundcubemail/program/lib/Roundcube/rcube_imap_generic.php:991
[0x00007f55aa813930] connect() /opt/www/roundcubemail/program/lib/Roundcube/rcube_imap.php:172
[0x00007f55aa813800] connect() /opt/www/roundcubemail/program/lib/Roundcube/rcube_imap.php:248
[0x00007f55aa813790] check_connection() /opt/www/roundcubemail/program/lib/Roundcube/rcube_imap.php:2955
[0x00007f55aa813650] list_folders_subscribed_direct() /opt/www/roundcubemail/program/lib/Roundcube/rcube_imap.php:2914
[0x00007f55aa813570] list_folders_subscribed() /opt/www/roundcubemail/program/actions/mail/check_recent.php:53
[0x00007f55aa813300] run() /opt/www/roundcubemail/program/include/rcmail.php:282
[0x00007f55aa8131d0] action_handler() /opt/www/roundcubemail/index.php:278

I saw the following error log in /var/log/dovecot/dovecot.log

Jul 24 18:48:39 ns8 dovecot: master: Warning: service auth { client_limit=1000 } is lower than required under max. load (1400)

So I updated dovecot.conf to include the following:

service auth {
    client_limit=5000

The error message disappeared, but the problems persisted.

Any ideas of what could be causing this?

----

Spider Email Archiver: On-Premises, lightweight email archiving software developed by iRedMail team. Supports Amazon S3 compatible storage and custom branding.

2

Re: 502 Bad Gateway - nginx

grupow wrote:

The error message disappeared, but the problems persisted.

Please check Dovecot log file again, it may reports similar warnings, fix them too.

3

Re: 502 Bad Gateway - nginx

ZhangHuangbin wrote:
grupow wrote:

The error message disappeared, but the problems persisted.

Please check Dovecot log file again, it may reports similar warnings, fix them too.

There is indeed another message:
Jul 24 19:01:27 ns8 dovecot: config: Warning: service anvil { client_limit=1000 } is lower than required under max. load (1303)

But the last entry is from 1 hour ago, and I do not see "service anvil" anywhere in dovecot.conf

Shall I just add the following?

service anvil {
    client_limit=5000
}

4

Re: 502 Bad Gateway - nginx

I've added service anvil settings above, and the error message disappeared. However, Roundcube is still super slow whilst loading.


I see this in  /var/log/nginx/error.log:

2023/07/25 05:27:28 [error] 967#967: *91692 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 85.240.81.200, server: webmail.grupow.com.br, request: "GET /?_task=mail&_caps=pdf%3D1%2Cflash%3D0%2Ctiff%3D0%2Cwebp%3D1%2Cpgpmime%3D0&_uid=70538&_mbox=INBOX&_framed=1&_action=preview HTTP/2.0", upstream: "fastcgi://127.0.0.1:9999", host: "webmail.grupow.com.br", referrer: "https://webmail.grupow.com.br/"
2023/07/25 05:27:58 [error] 967#967: *73853 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 143.255.223.49, server: webmail.grupow.com.br, request: "POST /?_task=mail&_action=refresh HTTP/2.0", upstream: "fastcgi://127.0.0.1:9999", host: "webmail.grupow.com.br", referrer: "https://webmail.grupow.com.br/"

Any thoughts?

5

Re: 502 Bad Gateway - nginx

- Does this issue happen to all webmail users, or just few of them? If just few, are they large mailboxes with few GB size?
- How many mail users do you have on this server?
- How much memory does this server have?