1. 程式人生 > 其它 >Request Line is too large (xxxx > 4094) 問題處理

Request Line is too large (xxxx > 4094) 問題處理

那曾經使我悲傷過的一切,也是我最熱愛過的一切。

#1 解決方法

4094是gunicorn的預設GET請求長度限制,報 Request Line is too large (xxxx > 4094) 可先確認是否為gunicorn配置問題。通過以下命令檢視gunicorn相關配置引數:

gunicorn --help
  --limit-request-line INT
                        The maximum size of HTTP request line in bytes. [4094]
  --limit-request-fields INT
                        Limit the number of HTTP headers fields in a request. [100]
  --limit-request-field_size INT
                        Limit the allowed size of an HTTP request header field. [8190]

可知,預設GET請求長度限制為4094位元組,故在gunicorn配置檔案中新增:

# Google(chrome)對URL的長度限制為8182位元組。
limit_request_line = 8182

這裡配置為8182的原因:

IE瀏覽器對URL的長度現限制為2048位元組。
360極速瀏覽器對URL的長度限制為2118位元組。
Firefox(Browser)對URL的長度限制為65536位元組。
Safari(Browser)對URL的長度限制為80000位元組。
Opera(Browser)對URL的長度限制為190000位元組。
Google(chrome)對URL的長度限制為8182位元組。

重啟服務即可。

#2 可能存在的其他問題

若未能解決,可以檢查所使用的代理,若為Nginx,檢查 nginx 配置檔案是否配置了足夠的大小:

client_max_body_size 100g;
client_header_buffer_size 512k;
large_client_header_buffers 4 512k;

還有就是注意上面提到的瀏覽器支援的最大長度限制。

#3 參考

1.gunicorn文件:https://docs.gunicorn.org/en/stable/settings.html#limit-request-line
2.Http協議中的各種長度限制總結:https://sites.google.com/site/gzhpwiki/home/guo-cheng-shi-jian/http-xie-yi-zhong-de-ge-zhong-zhang-du-xian-zhi-zong-jie

感謝閱讀,如有問題,請批評指正,謝謝。