【发布时间】:2019-11-23 21:43:40
【问题描述】:
当重定向的 POST 请求没有 Content-Length 时遇到问题。
首先遇到 AWS ALB 及其 301 for HTTP => HTTPS 重定向的问题,并认为这是 ALB 本身的问题。
然后只配置一个普通的 NGINX 与 HTTP 80 服务器和 HTTP 443 服务器:
server {
listen 80;
...
location / {
return 302 https://example.com$request_uri;
}
}
server {
listen 443 ssl;
...
location / {
proxy_pass http://localhost:8081;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-SSL on;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
在上游,我有一个简单的 Python 网络服务器来监听 8081 端口。
然后,如果直接向 443 端口运行请求 - 一切正常。 当我向端口 HTTP 80 发出请求时,会导致 302 重定向 - Python 应用程序说:
content_length = int(self.headers['Content-Length']) # <--- Gets the size of data TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType' ```
即self.headers['Content-Length'] == NoneType.
curl 显示数据时:
$ curl -vL -X POST http://example.com/ -d "param1=value1¶m2=value2"
...
< HTTP/1.1 502 Bad Gateway
< Server: nginx/1.10.3
...
< Content-Type: text/html
< Content-Length: 173
我不确定这是否是与 NGINX 相关的问题(再次 - 最初在 AWS Application Load Balancer 上遇到),但无论如何......
【问题讨论】:
-
找到解决方案,待全面测试后添加到这里。