【发布时间】:2021-02-04 10:10:57
【问题描述】:
我想在我的网站上启用相对较长的 URL。
在 Python 中,它工作得很好:
import requests
base_url = 'https://myurl.com'
client = requests.session()
gs = ['FAM20558-i1-1.1']
for i in [100,1000,1100]:
r = client.get(url=f'{base_url}/api/validate-genomes', params={'genomes[]': gs * i})
print(i, r.text)
输出:
100 {"success": true}
1000 {"success": true}
1100 <html>
<head><title>502 Bad Gateway</title></head>
<body bgcolor="white">
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx/1.14.1</center>
</body>
</html>
所以在i=1000 之前它可以正常工作,这就是我所需要的。
对于i=300,the URL 的长度为 9071 个字符。根据 sys.getsizeof 的大小:9120 字节。它看起来像这样:https://myurl.com/api/validate-genomes/?genomes%5B%5D=FAM20558-i1-1.1&genomes%5B%5D=FAM20558-i1-1.1&...
但是当我尝试将 URL 卷曲或将此 URL 复制到浏览器中时,它不起作用!这种长度的 ajax 请求也不起作用。这是为什么?我该如何解决? (带有i=100 的请求总是有效的。)
CURL 输出 (curl --http2 -v $URL):
> Host: myurl.com
> user-agent: curl/7.71.1
> accept: */*
>
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* old SSL session ID is stale, removing
* Connection state changed (MAX_CONCURRENT_STREAMS == 128)!
* TLSv1.3 (IN), TLS alert, close notify (256):
* Empty reply from server
* Closing connection 0
* TLSv1.3 (OUT), TLS alert, close notify (256):
curl: (52) Empty reply from server
在 nginx access.log 中,我看到:
<MY IP> - - [04/Feb/2021:11:06:58 +0100] "-" 000 0 "-" "-" "-"
nginx error.log 没有变化。
相关的 nginx 配置(不确定是否重要):
upstream django {
server unix:///path/to/socket.sock;
}
server {
listen 443 ssl http2 default_server;
client_max_body_size 10M;
uwsgi_buffer_size 128k;
uwsgi_buffers 12 128k;
uwsgi_busy_buffers_size 256k;
client_header_buffer_size 5120k;
large_client_header_buffers 16 5120k;
location / {
uwsgi_pass django;
include /etc/nginx/uwsgi_params;
}
}
#EDIT:我知道在这种情况下,POST 请求更有意义。但我想在别处使用长 URL,这是演示问题的便捷方式。
【问题讨论】: