目录
a.注释#if (APR_MAJOR_VERSION < 1)代码:
b.把所有的remote_addr替换成client_addr
1) httpd.conf 加上LoadModule bw_module modules/mod_bw.so
1、下载
下载地址:http://bwmod.sourceforge.net/
wget http://bwmod.sourceforge.net/files/mod_bw-0.7.tgz
目前是0.7版本
2、解压
tar -xzf mod_bw-0.7.tgz
3、编译安装
1)修改代码
由于apache2.2 到2.4 api有所改变详细地址http://httpd.apache.org/docs/2.4/developer/new_api_2_4.html
a.注释#if (APR_MAJOR_VERSION < 1)代码:
/* Compatibility for ARP < 1
#if (APR_MAJOR_VERSION < 1)
#define apr_atomic_inc32 apr_atomic_inc
#define apr_atomic_dec32 apr_atomic_dec
#define apr_atomic_add32 apr_atomic_add
#define apr_atomic_cas32 apr_atomic_cas
#define apr_atomic_set32 apr_atomic_set
#endif
*/
报错内容:
ERROR:
httpd: Syntax error on line 153 of /www/server/apache/conf/httpd.conf: Cannot load modules/mod_bw.so into server: /www/server/apache/modules/mod_bw.so: undefined symbol: apr_atomic_set
b.把所有的remote_addr替换成client_addr
报错内容:
mod_bw.c: In function ‘get_bw_rate’:
mod_bw.c:484:59: error: ‘conn_rec’ {aka ‘struct conn_rec’} has no member named ‘remote_addr’
484 | if (apr_ipsubnet_test(e[i].x.ip, r->connection->remote_addr)) {
| ^~
mod_bw.c: In function ‘get_maxconn’:
mod_bw.c:567:59: error: ‘conn_rec’ {aka ‘struct conn_rec’} has no member named ‘remote_addr’
567 | if (apr_ipsubnet_test(e[i].x.ip, r->connection->remote_addr)) {
| ^~
mod_bw.c: In function ‘get_sid’:
mod_bw.c:612:59: error: ‘conn_rec’ {aka ‘struct conn_rec’} has no member named ‘remote_addr’
612 | if (apr_ipsubnet_test(e[i].x.ip, r->connection->remote_addr)) {
| ^~
mod_bw.c: In function ‘update_counters’:
apxs:Error: Command failed with rc=65536
2)编译
cd mod_bw
/www/server/apache/bin/apxs -c -i mod_bw.c
![](https://i-blog.csdnimg.cn/blog_migrate/184f90564cfb2dae799584f57e127636.png)
4、配置apache
1) httpd.conf 加上LoadModule bw_module modules/mod_bw.so
2) 网站配置
详细配置可以参考mod_bw.txt
<VirtualHost *:80>
ServerAdmin webmaster@example.com
DocumentRoot "/www"
ServerName 301ac043.test
ServerAlias test
BandwidthModule On
ForceBandWidthModule On
Bandwidth all 2048000
MinBandwidth all 1024000
LargeFileLimit * 500 50000
MaxConnection all 10
主要参数说明
1) BandWidth localhost 0 //对localhost不限速
2) BandWidth 8.8.8.8 102400 //对8.8.8.8限速为100KB
3) MinBandWidth all 10240 //保证每个客户端最高速度可达10KB
4) LargeFileLimit .jpg 100 10240 //jpg文件超过100KB) 限速10KB
5) 自定义510报错
ErrorDocument 510 /errors/maxconexceeded.html
BandWidthError 510
6) MaxConnection all 10 //所有ip最大连接数为10
7) MaxConnection 8.8.8.8 5 //8.8.8.8最大连接数为5
5、测试
将最大连接数设置小点,如: MaxConnection all 1 然后打开开发者工具,不断的按F5刷新页面页面,就会出现canceled