CentOS7

Apache httpd : mod_limitipconn を利用する

mod_limitipconn モジュールを有効にして、IP アドレス単位での同時接続数を制限します。

mod_limitipconn をインストールします。

# EPEL からインストール
[root@localhost ~]# yum --enablerepo=epel -y install mod_limitipconn

mod_limitipconn の設定です。

[root@localhost ~]# vi /etc/httpd/conf.d/limitipconn.conf
# デフォルトは制限なし
MaxConnPerIP 0
# /limit 配下に設定
<Location /limit>
# 同一 IP からの最大同時接続数を 3 に制限
MaxConnPerIP 3
# MIME タイプ が text/* のものは制限しない
NoIPLimit text/*
</Location>
# /limit2 配下に設定
<Location /limit2>
# 同一 IP からの最大同時接続数を 2 に制限
MaxConnPerIP 2
# MIME タイプ が application/x-tar のみ制限する
OnlyIPLimit application/x-tar
</Location>
[root@localhost ~]# systemctl restart httpd

httpd-tools パッケージに付属のベンチマークツール「ab」コマンドを用いて、動作確認します。

サーバーの性能等、条件によっては同時接続と見なされず、期待した通りの結果が出ない場合もあるので、何度か試してみるとよいでしょう。

ちなみに、注意点として、limitipconn の制限は、設定したロケーションへのみではありません。

例えば、上記設定をした状態で、同一 IP から制限の設定をしていない / 直下のファイルに 3 セッション同時にアクセスしている最中に、さらに制限の設定をした /limit/xxx.gif にアクセスしてもアクセス不可となります。

制限した設定にアクセスがあったその場合は、同一 IP から / 配下全てに対するセッション数が制限の対象になるという仕様になっています。

[root@www html]# ab -n 10 -c 10 http://localhost/limit/index.html
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient).....done

Server Software: Apache/2.4.6
Server Hostname: localhost
Server Port: 80

Document Path: /limit/index.html
Document Length: 130 bytes

Concurrency Level: 10
Time taken for tests: 0.004 seconds
Complete requests: 10
Failed requests: 0
Write errors: 0
Total transferred: 3910 bytes
HTML transferred: 1300 bytes
Requests per second: 2223.21 [#/sec] (mean)
Time per request: 4.498 [ms] (mean)
Time per request: 0.450 [ms] (mean, across all concurrent requests)
Transfer rate: 848.90 [Kbytes/sec] received
.....
.....
[root@localhost html]# ab -n 10 -c 10 http://localhost/limit/test.gif
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient).....done


Server Software: Apache/2.4.6
Server Hostname: localhost
Server Port: 80

Document Path: /limit/test.gif
Document Length: 228 bytes

Concurrency Level: 10
Time taken for tests: 0.005 seconds
Complete requests: 10
Failed requests: 7
(Connect: 0, Receive: 0, Length: 7, Exceptions: 0)
Write errors: 0
Non-2xx responses: 7
Total transferred: 4838 bytes
HTML transferred: 2777 bytes
Requests per second: 2182.45 [#/sec] (mean)
Time per request: 4.582 [ms] (mean)
Time per request: 0.458 [ms] (mean, across all concurrent requests)
Transfer rate: 1031.12 [Kbytes/sec] received
.....
.....
[root@localhost ~]# ab -n 10 -c 10 http://localhost/limit2/test.tar
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient).....done


Server Software: Apache/2.4.6
Server Hostname: localhost
Server Port: 80

Document Path: /limit2/test.tar
Document Length: 10240 bytes

Concurrency Level: 10
Time taken for tests: 0.006 seconds
Complete requests: 10
Failed requests: 8
(Connect: 0, Receive: 0, Length: 8, Exceptions: 0)
Write errors: 0
Non-2xx responses: 8
Total transferred: 24900 bytes
HTML transferred: 22872 bytes
Requests per second: 1785.40 [#/sec] (mean)
Time per request: 5.601 [ms] (mean)
Time per request: 0.560 [ms] (mean, across all concurrent requests)
Transfer rate: 4341.44 [Kbytes/sec] received
.....
.....

トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2018-09-03 (月) 10:38:20