【问题标题】:Nginx returns 502 to browsers but works fine with curlNginx 向浏览器返回 502,但在 curl 上运行良好
【发布时间】:2021-04-13 08:05:11
【问题描述】:

我有一个在 kubernetes 集群中运行的 MediaWiki。 kubernetes 集群位于 nginx 代理后面,配置如下:

worker_processes 4;
worker_rlimit_nofile 40000;

events {
    worker_connections 1024;
}

http {
    upstream rancher {
        server 192.168.122.90:80;
    }

    map $http_upgrade $connection_upgrade {
        default Upgrade;
        ''      close;
    }

    server {
        listen 443 ssl http2;
        server_name .domain;

        ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt;
        ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;

        location / {
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_set_header X-Forwarded-Port $server_port;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://rancher;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;
            # This allows the ability for the execute shell window to remain open for up to 15 minutes. Without this parameter, the default is 1 minute and will automatically close.
            proxy_read_timeout 900s;
            proxy_connect_timeout 75s;
        }
    }

    server {
        listen 80 default_server;
        server_name _;
        return 301 https://$host$request_uri;
    }
}

我可以进入 wiki 的主页,但必须先登录才能使用它。当我单击使用 OAuth2 登录时,我从 nginx 代理服务器获得 502 状态(nginx 报告上游过早地结束了连接)。如果我使用 curl 执行相同的请求,我会得到一个 302,其中包含预期的授权端点的位置。我真的不明白为什么会这样。不使用代理并直接访问集群(从 vm 主机)正常工作,但这不是我想要的。

【问题讨论】:

    标签: nginx kubernetes


    【解决方案1】:

    所以这个问题与 nginx 和 kubernetes 无关。这是 mediawiki 的一个问题,压缩有一些有趣的行为。查看更多here,如果有人遇到类似的事情:)

    【讨论】:

      猜你喜欢
      • 2023-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-18
      • 2019-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多