@mrz1
2018-02-01T12:32:17.000000Z
字数 4228
阅读 1400
配置文件
ServerTokens OS //默认
[root@centos7 ~]#curl -I 172.18.103.167HTTP/1.1 403 ForbiddenDate: Sat, 27 Jan 2018 06:06:14 GMTServer: Apache/2.2.15 (CentOS) //服务器版本非常仔细Accept-Ranges: bytesContent-Length: 4961Connection: closeContent-Type: text/html; charset=UTF-8
ServerTokens prod //修改后
[root@centos7 ~]#curl -I 172.18.103.167HTTP/1.1 403 ForbiddenDate: Sat, 27 Jan 2018 06:07:06 GMTServer: Apache //这里显示用什么服务器不会显示版本Accept-Ranges: bytesContent-Length: 4961Connection: closeContent-Type: text/html; charset=UTF-8
绑定到特定的IP地址和/或端口(1) 省略IP表示为本机所有IP(2) Listen指令至少一个,可重复出现多次Listen 80Listen 8080示例:Listen 192.168.1.100:8080Listen 80
连接建立,每个资源获取完成后不会断开连接,而是继续等待其它的请求完成,默认关闭持久连接断开条件:数量限制:100时间限制:以秒为单位,httpd-2.4 支持毫秒级副作用:对并发访问量较大的服务器,持久连接功能会使用有些请求得不到响应折衷:使用较短的持久连接设置:KeepAlive On|Off //开关KeepAliveTimeout 15 //超时是时间15秒MaxKeepAliveRequests 100 //最大连接请求测试:telnet IP port(端口)GET /URL(路径) HTTP/1.1host: 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/httpdHTTPD=/usr/sbin/httpd.worker重启服务生效pstree -p|grep httpd查看进程和线程Httpd2.4与之不同以动态模块方式提供配置文件:/etc/httpd/conf.modules.d/00-mpm.confhttpd –M |grep mpm 重启服务生效pstree -p|grep httpd 查看进程和线程
<IfModule prefork.c>StartServers 8MinSpareServers 5MaxSpareServers 20ServerLimit 256 最多进程数,最大20000MaxClients 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.soLoadModule 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.htmlThis 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 requestsCompleted 2000 requestsCompleted 3000 requestsCompleted 4000 requestsCompleted 5000 requestsCompleted 6000 requestsCompleted 7000 requestsCompleted 8000 requestsCompleted 9000 requestsCompleted 10000 requestsFinished 10000 requestsServer Software: ApacheServer Hostname: 172.18.103.167Server Port: 80Document Path: /index.htmlDocument Length: 11 bytesConcurrency Level: 2000Time taken for tests: 3.059 secondsComplete requests: 10000Failed requests: 0Write errors: 0Total transferred: 2621834 bytesHTML transferred: 110077 bytesRequests 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] receivedConnection Times (ms)min mean[+/-sd] median maxConnect: 0 80 356.2 1 3014Processing: 0 127 422.8 16 1946Waiting: 0 126 422.8 16 1946Total: 12 207 676.6 17 3044Percentage of the requests served within a certain time (ms)50% 1766% 1775% 1880% 2190% 5995% 286598% 292399% 2947100% 3044 (longest request)