[Nginx] 解決 Request Header Or Cookie Too Large

在某個系統中有使用 Nginx 做負載均衡,在使用某些帳號登入時出現以下錯誤畫面:

    
400 Bad Request
Request Header Or Cookie Too Large
nginx/1.18.0 (Ubuntu)
    

從畫面中可以很簡單的得知問題是請求的 Header 或 Cookie 太過龐大。既然沒有辦法解決提出問題的人,我們只好老老實實的解決問題。

要解決也不難,只要修改 Nginx 的設定檔,此設定檔位於 /etc/nginx/nginx.conf ,只要放寬以下兩個設定值的限制即可:
    
http {
    client_header_buffer_size   4k;    # 預設 1k
    large_client_header_buffers 4 32k; # 預設 4 8k
}
    

如果此指令以被設定,匯出現 directive is duplicate in xxx ,不需要新增設定值,調整原本的設定即可。

參考資料:
Nginx - Module ngx_http_core_module

留言