@mrz1
2018-02-01T12:32:17.000000Z
字数 4228
阅读 1287
配置文件
ServerTokens OS //默认
[root@centos7 ~]#curl -I 172.18.103.167
HTTP/1.1 403 Forbidden
Date: Sat, 27 Jan 2018 06:06:14 GMT
Server: Apache/2.2.15 (CentOS) //服务器版本非常仔细
Accept-Ranges: bytes
Content-Length: 4961
Connection: close
Content-Type: text/html; charset=UTF-8
ServerTokens prod //修改后
[root@centos7 ~]#curl -I 172.18.103.167
HTTP/1.1 403 Forbidden
Date: Sat, 27 Jan 2018 06:07:06 GMT
Server: Apache //这里显示用什么服务器不会显示版本
Accept-Ranges: bytes
Content-Length: 4961
Connection: close
Content-Type: text/html; charset=UTF-8
绑定到特定的IP地址和/或端口
(1) 省略IP表示为本机所有IP
(2) Listen指令至少一个,可重复出现多次
Listen 80
Listen 8080
示例:
Listen 192.168.1.100:8080
Listen 80
连接建立,每个资源获取完成后不会断开连接,而是继续等待其它的请求完成,默认关闭持久连接
断开条件:数量限制:100
时间限制:以秒为单位,
httpd-2.4 支持毫秒级
副作用:对并发访问量较大的服务器,持久连接功能会使用有些请求得不到响应
折衷:使用较短的持久连接
设置:
KeepAlive On|Off //开关
KeepAliveTimeout 15 //超时是时间15秒
MaxKeepAliveRequests 100 //最大连接请求
测试:
telnet IP port(端口)
GET /URL(路径) HTTP/1.1
host: ip(随便写)
prefork, worker, event(测试阶段)
httpd-2.2不支持同时编译多个模块,所以只能编译时选定一个;rpm安装的包提供三个二进制程序文件,分别用于实现对不同MPM机制的支持
确认方法:ps aux | grep httpd
默认为/usr/sbin/httpd, 即prefork模式
查看模块列表
查看静态编译的模块
httpd -l
查看静态编译及动态装载的模块
httpd –M
动态模块加载:不需重启即生效
动态模块路径/usr/lib64/httpd/modules/
更换使用的httpd程序:
/etc/sysconfig/httpd
HTTPD=/usr/sbin/httpd.worker
重启服务生效
pstree -p|grep httpd查看进程和线程
Httpd2.4与之不同
以动态模块方式提供
配置文件:/etc/httpd/conf.modules.d/00-mpm.conf
httpd –M |grep mpm 重启服务生效
pstree -p|grep httpd 查看进程和线程
<IfModule prefork.c>
StartServers 8
MinSpareServers 5
MaxSpareServers 20
ServerLimit 256 最多进程数,最大20000
MaxClients 256 最大并发
MaxRequestsPerChild 4000 子进程最多能处理的请求数量。在处理MaxRequestsPerChild 个请求之后,子进程将会被父进程终止,这时候子进程占用的内存就会释放(为0时永远不释放)
</IfModule>
<IfModule worker.c>
StartServers 4 //进程数
MaxClients 300 //最大连接数
MinSpareThreads 25 //最小的空闲线程
MaxSpareThreads 75 //最大的空闲线程
ThreadsPerChild 25 //每个进程带有的线程数
MaxRequestsPerChild 0 //无限制
</IfModule>
加载动态模块配置
/etc/httpd/conf/httpd.conf
配置指定实现模块加载格式:
LoadModule <mod_name> <mod_path>
模块文件路径可使用相对路径:
相对于ServerRoot(默认/etc/httpd)
示例:
[root@centos6 ~]#cat //etc/httpd/conf/httpd.conf
// 在150行后.so后缀的都是动态模块
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule auth_digest_module modules/mod_auth_digest.so
··········
DocumentRoot "/path" //页面路径 292行
文档路径映射:
DocumentRoot指向的路径为URL路径的起始位置
默认:
DocumentRoot "/var/www/html" 网站默认路径
http://HOST:PORT/index.html
--> /var/www/html/index.html
示例:
DocumentRoot "/app/data"
http://HOST:PORT/index.html
--> /app/data/index.html
注意:
SELinux和iptables的状态
不写路径只有ip默认寻找的是index.html文件,如果不存在会调用/etc/httpd/conf.d/welcome.conf 这里面配置的默认文件(默认的文件会暴露服务器版本 所以welcome.conf修改名字任意 找不到此文件就会403)
定义站点主页面
DirectoryIndex index.html index.html.var //402行
定义了默认找index.html文件或者添加别的文件找不到前面就访问后面文件
可基于两种机制指明对哪些资源进行何种访问控制
访问控制机制有两种:客户端来源地址,用户账号
文件系统路径
<Directory "/path">
...文件夹
</Directory>
<File "/path/file">
...文件
</File>
<FileMatch "PATTERN">
...正则
</FileMatch>
URL路径:
<Location "">
...
</Location>
<LocationMatch "">
...
</LocationMatch>
示例:
<FilesMatch "\.(gif|jpe?g|png)$">
<Files "?at.*"> 通配符
<Location /status>
<LocationMatch "/(extra|special)/data">
安装: yum install httpd-tools
命令:
ab -c 2000 -n 10000 http://172.18.103.167/index.html
-c 并发2000
-n 最多10000个
ulimit -a 显示当前的各种用户进程限制
[root@centos6 html]#ab -c 2000 -n 10000 http://172.18.103.167/index.html
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 172.18.103.167 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests
Server Software: Apache
Server Hostname: 172.18.103.167
Server Port: 80
Document Path: /index.html
Document Length: 11 bytes
Concurrency Level: 2000
Time taken for tests: 3.059 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Total transferred: 2621834 bytes
HTML transferred: 110077 bytes
Requests per second: 3269.55 [#/sec] (mean)
Time per request: 611.705 [ms] (mean)
Time per request: 0.306 [ms] (mean, across all concurrent requests)
Transfer rate: 837.13 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 80 356.2 1 3014
Processing: 0 127 422.8 16 1946
Waiting: 0 126 422.8 16 1946
Total: 12 207 676.6 17 3044
Percentage of the requests served within a certain time (ms)
50% 17
66% 17
75% 18
80% 21
90% 59
95% 2865
98% 2923
99% 2947
100% 3044 (longest request)