小型網站的搜尋遭機器人灌爆,作者用 PHP 和 nginx 調整讓網站恢復穩定
Bots hammered our search box and took the site down. The fix was 5 lines of PHP and one nginx number.
重點導讀
搜尋頁被大量機器人請求打滿時,共用資料庫變慢,連首頁也得等上 5 到 12 秒。
- 作者先替前端呼叫 API 加上 5 秒期限,讓資料卡住時首頁仍能顯示。
- 隔天再限制搜尋最多處理 5 個詞、移除只計算筆數時多餘的排序,並把 nginx 同時允許的搜尋數從 16 降到 4。這些改動讓慢搜尋較不容易拖垮整個網站。
- 作者也提醒,小型網站應替伺服器請求設期限,並限制搜尋輸入和同時處理的數量。
AI 伴隨問答
針對這篇報導有疑問?可直接點選快捷問題或向 AI 追問背景脈絡與技術細節:
信源出處dev.to
Bots hammered our search box and took the site down. The fix was 5 lines of PHP and one nginx number.
本文為 888news 精選之重點導讀。若需閱讀作者完整原文、技術細節與官方討論,請前往原始網站。
來源: Dev.to Top Tech (dev.to)
開啟原文