Nginx在100续401响应后未收到第二个请求

问题描述 投票:1回答:1

对于以下配置,请求2没有反映在nginx中。没有错误日志,对于请求2的访问日志中也没有任何内容。

此问题仅在引入100-Continue,401 Unauthored后才开始出现。如果请求1由代理服务器响应101,则一切就绪(结束了Websocket连接)。

预期的行为:第二个请求应成功到达代理,然后到达代理服务器。之后,它将隐藏到websocket连接。

Nginx配置

server {
    listen 443 ssl;
    server_name admin.example.com;
    ssl_certificate       /etc/nginx/server.pem;
    ssl_certificate_key   /etc/nginx/key.pem;
    ssl_session_cache shared:SSL:5m;
    ssl_protocols TLSv1.2;
    ssl_dhparam /etc/ssl/certs/dhparam.pem;
    ssl_ecdh_curve secp384r1;
    server_name_in_redirect on;
    client_max_body_size 100m;

    location /my_line/ {
        proxy_pass        https://y.y.y.y/;
        proxy_set_header  Host y.y.y.y;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $http_connection;
        proxy_ignore_client_abort on;
        proxy_buffering off;
        proxy_http_version 1.1;
        proxy_set_header Origin '';
        keepalive_timeout 100s;
        proxy_set_header Expect $http_expect;
        proxy_read_timeout 7200;
    }

    error_page  404              /index.html;
    location / {
        root   /usr/share/nginx/html;
        add_header X-Frame-Options DENY always;
        add_header X-Content-Type-Options nosniff always;
        add_header X-XSS-Protection "1; mode=block"  always;
    }
}

请求1:

GET /myserver/my_line/84620 HTTP/1.1
Connection: Upgrade
Authorization: Basic ODQ2MjA6c3MxOE1VRUs5UEF6RTB5eHoyVmpSZ0Roc3VyV0tCcA==
User-Agent: IPOffice/WebSocketClient/
Host: x.x.x.x
Upgrade: websocket
Sec-WebSocket-Key: DhaIyjupEbTHXQvX3asVeA==
Sec-WebSocket-Protocol: Web_Proxy
Sec-WebSocket-Version: 13
Sec-WebSocket-Extensions: mux

响应1

HTTP/1.1 100 Continue
Server: nginx
Date: Mon, 09 Dec 2019 16:33:51 GMT
Connection: keep-alive

响应2

HTTP/1.1 401 Unauthorized
Date: Mon, 09 Dec 2019 16:33:51 GMT
Expires: Mon, 09 Dec 2019 16:34:51 GMT
Cache-Control: private,max-age=60
WWW-Authenticate: Digest realm="WebSocket Group@myapp", domain="", nonce="f9beaf5521a1cdf078362b68a4332df5", algorithm=MD5
Server: MyServer/
X-Frame-Options: DENY
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Strict-Transport-Security: max-age=31536000
Content-Length: 0

请求2

GET /myserver/my_line/84620 HTTP/1.1
Connection: Upgrade
Authorization: Digest username="84620", realm="WebSocket Group@myapp", nonce="f9beaf5521a1cdf078362b68a4332df5", uri="/myserver/my_line/84620", response="5d8bb7c396724bb840da698c06f19629", algorithm=MD5, nc=00000056
User-Agent: MyApp/WebSocketClient/
Host: x.x.x.x
Upgrade: websocket
Sec-WebSocket-Key: DhaIyjupEbTHXQvX3asVeA==
Sec-WebSocket-Protocol: Web_Proxy
Sec-WebSocket-Version: 13
Sec-WebSocket-Extensions: mux

问题->第二个请求未反映在Nginx访问日志中,错误日志中没有任何内容。

nginx支持将请求代理到代理服务器,而不做任何其他自己拥有的事情。从客户端触发REQUEST2时,客户端与代理,代理与代理服务器之间的TCP连接保持不变。我怀疑nginx上的配置在连接和升级标头中出现了问题。我已经在nginx捕获了所有的wireshark,它清楚地表明tcp连接已就位,请求2被nginx确认。只是nginx没有对其进行处理-好像它进入了黑洞并且没有从中出来。

请求您的专家帮助。谢谢。

nginx websocket nginx-location nginx-config
1个回答
0
投票
https://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html

如果客户不打算发送请求正文,则它不得发送带有“ 100-continue”期望的Expect请求标头字段(第14.20节)。

这可能是挂起的原因,因为服务器可能正在等待永远不会到达的主体(用于请求1)。

© www.soinside.com 2019 - 2024. All rights reserved.