【问题标题】:NGINX + HTTPS causes 504 Gateway Timeout error for external requestsNGINX + HTTPS 导致外部请求的 504 Gateway Timeout 错误
【发布时间】:2026-01-24 01:20:02
【问题描述】:

我在我的 Raspberry Pi 上运行 nginx 服务器,使用 HTTP 协议似乎工作得很好。 最近,我决定为我的服务器添加 HTTPS 支持并从 Let's Encrypt 获得证书。 如果您从本地网络发送请求,它仍然像一个魅力。但是通过 HTTPS 的每个外部请求都以 504 Gateway Timeout 错误结束。

这是我的配置:

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    listen 443 ssl default_server;
    listen [::]:443 ssl default_server;

    root /var/www/html;

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html;

    server_name domain.name;

    ssl_session_cache shared:SSL:20m;
    ssl_session_timeout 180m;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

    ssl_prefer_server_ciphers on;
    ssl_ciphers ECDH+AESGCM:ECDH+AES256:ECDH+AES128:DHE+AES128:!ADH:!AECDH:!MD5;

    ssl_certificate /etc/letsencrypt/live/domain.name/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/domain.name/privkey.pem;
    ssl_trusted_certificate /etc/letsencrypt/live/domain.name/chain.pem;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }

    location ~ /.well-known {
        allow all;
        root /usr/share/nginx/html;
    }
}

【问题讨论】:

  • 您的 PI 是否分配了静态 IP?如果没有,那么您需要将路由器配置为将端口 80 和 443 转发到 rasp IP,这样它就可以工作了。否则本地网络后面的 rasp PI 无法访问,因此 504
  • @TarunLalwani,已配置 80 和 443 的静态 IP 和端口转发。
  • 但我认为请求仍未到达 nginx。您在访问日志中看到外部请求的任何内容吗?
  • @TarunLalwani,你是对的。仍然不知道是什么原因造成的,但是当我将端口转发从 443 -> 443 更改为 8081 -> 443 并向domain.name:8081 发送请求时,它起作用了。不过,还需要进一步调查。感谢您的帮助!

标签: ssl nginx https timeout http-status-code-504


【解决方案1】:

发现我的 ISP 默认启用了防火墙服务。它阻止了到 443 端口的所有连接。禁用它解决了我的问题。

【讨论】:

    最近更新 更多