knadh / listmonk

High performance, self-hosted, newsletter and mailing list manager with a modern dashboard. Single binary app.
https://listmonk.app
GNU Affero General Public License v3.0
14.57k stars 1.33k forks source link

502 Bad Gateway for /api/health and /api/events?type=error on admin/settings #1881

Closed GeistFighter closed 3 months ago

GeistFighter commented 3 months ago

Version:

Description of the bug and steps to reproduce: Hi all,

I recently installed Listmonk on my server, in Binary mode, with the aim of putting the Listmonk server on a local server only and accessible via a Nginx reverse proxy.

But apparently I'm getting 502 Bad Gateway errors when I make changes in admin/settings, in the console I'm also getting errors, but in the GUI there aren't any, I'd like to know where this is coming from, have I made a mistake or not?

To explain my configurations better, I've put everything on a local infrastructure so that I can share them with you.

Screenshots: image image

I'll also put the request logs in which you'll find the answers in 502. newsletter.testing.local_Archive [24-06-01 16-31-49].log

Nginx error logs : 2024/06/01 16:26:22 [error] 86006#86006: 2 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.8.1, server: newsletter.testing.local, request: "GET /api/health HTTP/2.0", upstream: "http://127.0.0.1:16670/api/health", host: "newsletter.testing.local", referrer: "https://newsletter.testing.local/admin/settings" 2024/06/01 16:26:23 [error] 86006#86006: 2 upstream prematurely closed connection while reading response header from upstream, client: 192.168.8.1, server: newsletter.testing.local, request: "GET /api/events?type=error HTTP/2.0", upstream: "http://127.0.0.1:16670/api/events?type=error", host: "newsletter.testing.local", referrer: "https://newsletter.testing.local/admin/settings" 2024/06/01 16:26:27 [error] 86006#86006: 2 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.8.1, server: newsletter.testing.local, request: "GET /api/health HTTP/2.0", upstream: "http://127.0.0.1:16670/api/health", host: "newsletter.testing.local", referrer: "https://newsletter.testing.local/admin/settings" 2024/06/01 16:26:32 [error] 86006#86006: 2 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.8.1, server: newsletter.testing.local, request: "GET /api/health HTTP/2.0", upstream: "http://127.0.0.1:16670/api/health", host: "newsletter.testing.local", referrer: "https://newsletter.testing.local/admin/settings"

No error on the service : image

My configuration

My config.toml : image

The service : image

My Nginx configuration : image

Thank you in advance for your answers!

MaximilianKohler commented 3 months ago

That's the error I got when I had a firewall issue.

GeistFighter commented 3 months ago

Hello MaximilianKohler, thank you for your reply !

I've disabled my firewall : image

but the problem is still there : image

GeistFighter commented 3 months ago

What's strange is that even if there are errors in the console, the site looks functional.

I think the problem is with the reverse proxy, because if you go directly via the IP address and port in the configuration it works without any errors in the console (I opened access to the port for the test, and set 0.0.0.0 in the listmonk configuration).

Do you have any ideas as to why the reverse proxy can causing these errors (I've tested the reverse proxy in 80 http and 443 https, and it makes no difference) ?

GeistFighter commented 3 months ago

Hi, do you think this could be due to my Nginx reverse proxy configuration not respecting certain routes?

https://listmonk.app/docs/configuration/#http-routes

knadh commented 3 months ago

This is most likely an Nginx routing issue. A 502 is thrown when the reverse proxy is unable to reach a backend, where the backend is down or it's unreachable/misconfigured.

GeistFighter commented 3 months ago

Where do you think the misconfiguration could have come from?