HTTPS 在 nginx 终止之后,Flask 怎么知道用户走的是 https?重定向和外部链接会不会变成 http?上传限制和流式响应经过 nginx 会怎样?这篇起一个真的 nginx 与 gunicorn,把每种配置的结果量出来。
/info → {'external': 'http://localhost:9603/info', 'host': 'localhost:9603', 'is_secure': False, 'remote_addr': '127.0.0.1', 'scheme': 'http'}
GET /dir(规则是 /dir/)→ 308 Location: http://localhost:9603/dir/nginx 是自己用 brew 装的,用自己的配置文件跑在非默认端口,证书是临时生成的自签证书(请求时关闭证书校验)。
/info → {'external': 'https://localhost:9606/info', 'host': 'localhost:9606', 'is_secure': True, 'remote_addr': '127.0.0.1', 'scheme': 'https'}
GET /dir(规则是 /dir/)→ 308 Location: https://localhost:9606/dir/
(gunicorn 自己把 X-Forwarded-Proto 翻译成了 wsgi.url_scheme) /info → {'external': 'https://localhost:9609/info', 'host': 'localhost:9609', 'is_secure': True, 'remote_addr': '127.0.0.1', 'scheme': 'https'}
GET /dir(规则是 /dir/)→ 308 Location: https://localhost:9609/dir/http://…/info?x=1 → 301 Location: https://127.0.0.1:9612/info?x=1
上传 500 KB → 200 ('512000')
上传 900 KB → 200 ('921600')
上传 1100 KB → 413 (nginx 直接拒绝,请求没有到达 Flask)
上传 3000 KB → 413 (nginx 直接拒绝,请求没有到达 Flask)
client_max_body_size 5m 后上传 3000 KB → 200proxy_buffering on 读到每一块数据的时间(ms): [1551, 1551, 1551, 1551, 1551] proxy_buffering off 读到每一块数据的时间(ms): [311, 617, 918, 1222, 1533]