[GH-ISSUE #98] 文件錯誤和建議 #210

Closed
opened 2026-03-13 17:03:32 +03:00 by kerem · 6 comments
Owner

Originally created by @ADeeeee on GitHub (Jun 24, 2022).
Original GitHub issue: https://github.com/ADD-SP/ngx_waf/issues/98

環境:

  • 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 版

問題:

waf_cc_deny
waf_cache

兩項設定不支援寫在 http 的 context 裡面,執行 nginx -t 就會顯示該錯誤

可能是新版 nginx 有做修正,但需要標示在文件上


題外話:

如全域開啟 waf_modescurity 看是否註記建議寫在 http 的區塊,避免寫在 server 或 location 讓 nginx 重啟會重複讀取大量一樣的規則,導致服務關閉和開啟要等非常久,並會吃掉大量的記憶體

本身 waf 的部份應該同理,但經測試後,讀取上感覺不出來差異,或許是我規則太少的緣故

Originally created by @ADeeeee on GitHub (Jun 24, 2022). Original GitHub issue: https://github.com/ADD-SP/ngx_waf/issues/98 環境: * 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 版 --- 問題: [waf_cc_deny](https://docs.addesp.com/ngx_waf/advance/directive.html#waf-cc-deny) [waf_cache](https://docs.addesp.com/ngx_waf/advance/directive.html#waf-cache) 兩項設定不支援寫在 http 的 context 裡面,執行 ```nginx -t``` 就會顯示該錯誤 可能是新版 nginx 有做修正,但需要標示在文件上 --- 題外話: 如全域開啟 waf_modescurity 看是否註記建議寫在 http 的區塊,避免寫在 server 或 location 讓 nginx 重啟會重複讀取大量一樣的規則,導致服務關閉和開啟要等非常久,並會吃掉大量的記憶體 本身 waf 的部份應該同理,但經測試後,讀取上感覺不出來差異,或許是我規則太少的緣故
Author
Owner

@ADD-SP commented on GitHub (Jun 27, 2022):


Current 版本的变化已经在文档中提示了,或许绿色不够显眼。


ngx_waf 应该不会重复读取 modsec 的规则,会自动从上级继承,而不是重新读取。

<!-- gh-comment-id:1167535385 --> @ADD-SP commented on GitHub (Jun 27, 2022): ![](https://user-images.githubusercontent.com/44437200/175982421-a1d6daeb-dd68-48d7-b1c8-1324e6f9b777.png) ![](https://user-images.githubusercontent.com/44437200/175982444-974c5682-7e41-415a-9455-817a10bdccf8.png) Current 版本的变化已经在文档中提示了,或许绿色不够显眼。 *** ngx_waf 应该不会重复读取 modsec 的规则,会自动从上级继承,而不是重新读取。
Author
Owner

@ADeeeee commented on GitHub (Jun 28, 2022):

阿不好意思,這樣支援的部份是我沒看清楚文件

了解,我這邊會再測試一下 waf_modsecurity 上下級同時設定是否會重新讀取,感謝信心加持

<!-- gh-comment-id:1168176079 --> @ADeeeee commented on GitHub (Jun 28, 2022): 阿不好意思,這樣支援的部份是我沒看清楚文件 了解,我這邊會再測試一下 waf_modsecurity 上下級同時設定是否會重新讀取,感謝信心加持
Author
Owner

@ADeeeee commented on GitHub (Jul 8, 2022):

不好意思我再重啟這個問題

用以下的條件來實測 nginx 是否會延遲讀取設定檔:

  1. 單獨在 http 段加上 WAF 啟動設定 (含 http 加上 modsecurity on)
  2. 在 http 及 server 段都加上 WAF 啟動設定 (含 http 加上 modsecurity on)
  3. http 及 server 都加上 modsecurity 啟動設定
  4. 共 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 功能就會完全失效,這個可能要特別備註注意

<!-- gh-comment-id:1178457337 --> @ADeeeee commented on GitHub (Jul 8, 2022): 不好意思我再重啟這個問題 ## 用以下的條件來實測 nginx 是否會延遲讀取設定檔: 1. 單獨在 http 段加上 WAF 啟動設定 (含 http 加上 modsecurity on) 2. 在 http 及 server 段都加上 WAF 啟動設定 (含 http 加上 modsecurity on) 3. http 及 server 都加上 modsecurity 啟動設定 4. 共 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 功能就會完全失效,這個可能要特別備註注意
Author
Owner

@stale[bot] commented on GitHub (Jul 21, 2022):

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 因为最近没有任何活动已经被标记,如果在此之后的一段时间内仍没有任何活动则会被关闭。感谢您对项目的支持。

<!-- gh-comment-id:1191636804 --> @stale[bot] commented on GitHub (Jul 21, 2022): 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 因为最近没有任何活动已经被标记,如果在此之后的一段时间内仍没有任何活动则会被关闭。感谢您对项目的支持。
Author
Owner

@stale[bot] commented on GitHub (Jul 29, 2022):

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 因为最近没有任何活动已经被标记,如果在此之后的一段时间内仍没有任何活动则会被关闭。感谢您对项目的支持。

<!-- gh-comment-id:1198850475 --> @stale[bot] commented on GitHub (Jul 29, 2022): 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 因为最近没有任何活动已经被标记,如果在此之后的一段时间内仍没有任何活动则会被关闭。感谢您对项目的支持。
Author
Owner

@stale[bot] commented on GitHub (Aug 10, 2022):

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 因为最近没有任何活动已经被标记,如果在此之后的一段时间内仍没有任何活动则会被关闭。感谢您对项目的支持。

<!-- gh-comment-id:1210085373 --> @stale[bot] commented on GitHub (Aug 10, 2022): 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 因为最近没有任何活动已经被标记,如果在此之后的一段时间内仍没有任何活动则会被关闭。感谢您对项目的支持。
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/ngx_waf#210
No description provided.