It's an email server that everyone else seems to be getting running with the same settings. For some reason it's not working for me, and none of the previous answers for "502 nginx docker" or "recv failed Connection reset by peer" have solved it. Maybe it has to do with my Nginx Vhost setup?
The site loads properly on serverIP:5870 and if I change proxy_pass http://127.0.0.1:5870; to proxy_pass http://example.com:5870; then it will load on example.com:5870. But it gives the 502 error when I visit the site without the port.
If I set proxy_pass http://127.0.0.1:5870; and visit example.com:5870 I get:
The connection for this site is not secure
example.com sent an invalid response.
Try running Windows Network Diagnostics.
ERR_SSL_PROTOCOL_ERROR
If I change proxy_pass to http://example.com:5870; example.com will load, but a "broken" page with basic text and the urls are http://localhost:9000/subscription/form".
Broken listmonk homepage image
docker-compose.yml:
version: "3.7"
x-app-defaults: &app-defaults
restart: unless-stopped
image: listmonk/listmonk:latest
ports:
- "5870:9000"
networks:
- listmonk
environment:
- TZ=Etc/UTC
x-db-defaults: &db-defaults
image: postgres:13
ports:
- "9432:5432"
networks:
- listmonk
environment:
- POSTGRES_PASSWORD=pw
- POSTGRES_USER=listmonk
- POSTGRES_DB=listmonk
restart: unless-stopped
healthcheck:
test: ["CMD-SHELL", "pg_isready -U listmonk"]
interval: 10s
timeout: 5s
retries: 6
services:
db:
<<: *db-defaults
container_name: listmonk_db
volumes:
- type: volume
source: listmonk-data
target: /var/lib/postgresql/data
app:
<<: *app-defaults
container_name: listmonk_app
depends_on:
- db
volumes:
- ./config.toml:/listmonk/config.toml
- ./uploads:/listmonk/uploads
networks:
listmonk:
volumes:
listmonk-data:
nginx config:
server {
listen 443 ssl;
server_name example.com;
location / {
proxy_pass http://127.0.0.1:5870;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
server {
listen 80;
server_name example.com;
location / {
return 301 https://$host$request_uri;
}
}
The nginx error log shows 2023/11/22 17:54:00 [error] 54579#54579: *2 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: <myip>, server: example.com, request: "GET / HTTP/2.0", upstream: "http://127.0.0.1:5870/", host: "example.com"
Search results for "recv failed 104 Connection reset by peer while reading response header from upstream" all say it's a php-fpm issue. But I haven't found any solutions. php-fpm:
sudo netstat -nlpt |grep 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 1175/php-fpm: maste
I've tried many variations of proxy_pass:
proxy_pass http://example.com:5870;proxy_pass http://<SERVER_IP>:5870;- same result as above.proxy_pass http://0.0.0.0:5870;same as 127.0.0.1:5870.proxy_pass http://example.com/;results in "ERR_TOO_MANY_REDIRECTS".proxy_pass http://listmonk_app:5870;,proxy_pass http://app:5870;, andproxy_pass http://listmonk:5870;all cause nginx errors.
I found this nginx resolving localhost on proxy pass and ran:
curl 127.0.0.1:5870
curl: (56) Recv failure: Connection reset by peer
curl 0.0.0.0:5870
curl: (56) Recv failure: Connection reset by peer
curl 127.0.0.1:9000
curl: (56) Recv failure: Connection reset by peer
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6738da252977 listmonk/listmonk:latest "./listmonk" 3 weeks ago Up 47 hours 0.0.0.0:5870->9000/tcp, :::5870->9000/tcp listmonk_app
f8d43916e568 postgres:13 "docker-entrypoint.s…" 3 weeks ago Up 47 hours (healthy) 0.0.0.0:9432->5432/tcp, :::9432->5432/tcp listmonk_db
sudo netstat -nlpt |grep 5870
tcp 0 0 0.0.0.0:5870 0.0.0.0:* LISTEN 2757/docker-proxy
tcp6 0 0 :::5870 :::* LISTEN 2762/docker-proxy
I tried some of the solutions here https://serverfault.com/questions/351212/nginx-redirects-to-port-8080-when-accessing-url-without-slash
proxy_set_header Host $host:$server_port; didn't seem to change anything.
I also tried
proxy_pass http://example.com:5870/;
proxy_redirect http://example.com:5870/ http://example.com/;
Maybe this NodeJs on nginx not working without a port number in the url is the answer, but I don't understand it.
It was a firewall issue. I disabled my firewall and it works.