ngx_waf
ngx_waf copied to clipboard
文件錯誤和建議
環境:
- Ubuntu 20.04.3 LTS
- nginx version: nginx/1.18.0 (Ubuntu) built with OpenSSL 1.1.1f 31 Mar 2020 TLS SNI support enabled
- ngx_waf: 照文件流程 compile 出來的 v10.1.1 Current 版
問題:
兩項設定不支援寫在 http 的 context 裡面,執行 nginx -t 就會顯示該錯誤
可能是新版 nginx 有做修正,但需要標示在文件上
題外話:
如全域開啟 waf_modescurity 看是否註記建議寫在 http 的區塊,避免寫在 server 或 location 讓 nginx 重啟會重複讀取大量一樣的規則,導致服務關閉和開啟要等非常久,並會吃掉大量的記憶體
本身 waf 的部份應該同理,但經測試後,讀取上感覺不出來差異,或許是我規則太少的緣故

Current 版本的变化已经在文档中提示了,或许绿色不够显眼。
ngx_waf 应该不会重复读取 modsec 的规则,会自动从上级继承,而不是重新读取。
阿不好意思,這樣支援的部份是我沒看清楚文件
了解,我這邊會再測試一下 waf_modsecurity 上下級同時設定是否會重新讀取,感謝信心加持
不好意思我再重啟這個問題
用以下的條件來實測 nginx 是否會延遲讀取設定檔:
- 單獨在 http 段加上 WAF 啟動設定 (含 http 加上 modsecurity on)
- 在 http 及 server 段都加上 WAF 啟動設定 (含 http 加上 modsecurity on)
- http 及 server 都加上 modsecurity 啟動設定
- 共 61 個 server vhost files
啟動設定:
# WAF
waf bypass;
waf_rule_path /etc/nginx/ngx_waf/rules/;
# modsecurity
waf_modsecurity on file=/etc/nginx/ngx_waf/modsecurity/modsecurity.conf;
結果:
單獨 http 啟用 WAF 和 modsecurity 設定,重複 10 次確認都差不多在 0.5s 左右:
$ time nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
real 0m0.492s
user 0m0.119s
sys 0m0.099s
http 和 server 啟用 WAF 設定,單獨 http 啟用 modsecurity 設定,重複 10 次確認都差不多在 1.3s 左右:
$ time nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
real 0m1.283s
user 0m0.418s
sys 0m0.168s
http 和 server 都啟用 WAF 和 modsecurity 設定,重複 10 次都在 1 分鐘左右:
$ time nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
real 1m17.599s
user 1m2.066s
sys 0m6.206s
這樣的結果看起來除了繼承 http 段之外,看起來都是 server 段會再重新讀取一次,才會有啟動時間上的差異?請再幫忙確認一下是否符合繼承上層不會重新讀取的概念
希望是不管怎麼寫都只要讀取一次就好,可以讓使用者有調整的彈性,並維持良好的效能
另外如 http 段有加上 WAF 啟動設定,而 server 只有加 waf bypass; 而沒加上 waf_rule_path,在 nginx 語法檢查上並不會出現錯誤,但 WAF 功能就會完全失效,這個可能要特別備註注意
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. 此 issue 因为最近没有任何活动已经被标记,如果在此之后的一段时间内仍没有任何活动则会被关闭。感谢您对项目的支持。
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. 此 issue 因为最近没有任何活动已经被标记,如果在此之后的一段时间内仍没有任何活动则会被关闭。感谢您对项目的支持。
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. 此 issue 因为最近没有任何活动已经被标记,如果在此之后的一段时间内仍没有任何活动则会被关闭。感谢您对项目的支持。