这是一个电子邮件服务器,其他人似乎都在以相同的设置运行。由于某种原因,它对我不起作用,并且之前“502 nginx docker”或“recv failed Connection Reset by Peer”的答案都没有解决它。也许这与我的 Nginx Vhost 设置有关?
该网站在 serverIP:5870 上正确加载,如果我将proxy_pass http://127.0.0.1:5870;
更改为
proxy_pass http://example.com:5870;
那么它将在 example.com:5870 上加载。但是当我访问没有端口的网站时,它会出现 502 错误。如果我设置
proxy_pass http://127.0.0.1:5870;
并访问 example.com:5870 我得到:
The connection for this site is not secure
example.com sent an invalid response.
Try running Windows Network Diagnostics.
ERR_SSL_PROTOCOL_ERROR
如果我将 proxy_pass 更改为 http://example.com:5870;
example.com 将加载,但带有基本文本的“损坏”页面和 URL 为 http://localhost:9000/subscription/form”。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 配置: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;
}
}
nginx 错误日志显示 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"
recv failed 104 Connection Reset by peer whileReading response header from upper”都说这是一个 php-fpm 问题。但我还没有找到任何解决方案。 PHP-FPM:
sudo netstat -nlpt |grep 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 1175/php-fpm: maste
我尝试了多种proxy_pass
变体:
proxy_pass http://example.com:5870;
proxy_pass http://<SERVER_IP>:5870;
- 与上面相同的结果。
proxy_pass http://0.0.0.0:5870;
与 127.0.0.1:5870 相同。
proxy_pass http://example.com/;
结果为“ERR_TOO_MANY_REDIRECTS”。
proxy_pass http://listmonk_app:5870;
、
proxy_pass http://app:5870;
和
proxy_pass http://listmonk:5870;
都会导致nginx错误。
nginx在代理通行证上解析本地主机并运行:
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
我在这里尝试了一些解决方案https://serverfault.com/questions/351212/nginx-redirects-to-port-8080-when-accessing-url-without-slash
proxy_set_header Host $host:$server_port;
似乎没有改变任何事情。我也尝试过
proxy_pass http://example.com:5870/;
proxy_redirect http://example.com:5870/ http://example.com/;
也许这个 NodeJs on nginx not work without a port number in the url 就是答案,但我不明白。