CentOS 6:html
程序环境web
配置文件:数据库
/etc/httpd/conf/httpd.confapache
/etc/httpd/conf.d/*.conf安全
服务脚本:bash
/etc/rc.d/init.d/httpd服务器
配置文件:/etc/sysconfig/httpd并发
主程序文件:ide
/usr/sbin/httpd测试
/usr/sbin/httpd.event
/usr/sbin/httpd.worker
日志文件目录:
/var/log/httpd
access_log:访问日志
error_log:错误日志
站点文档目录:
/var/www/html
配置文件的组成:
~]# grep "Section" /etc/httpd/conf/httpd.conf
### Section 1:Golbal Environment
### Section 2:'Main' server configuration
### Section 3:Virtual Hosts
经常使用配置:
一、修改监听的IP和Port
Listen [IP:]PORT
省略ip表示监听本机全部IP;Listen可重复出现屡次;
二、持久链接
Persistent Connection:链接创建,每一个资源获取完成后不会断开链接,而是继续等待其它的请求完成;
如何断开?
数量限制:100
时间限制:可配置
反作用:对并发访问量较大的服务器,持久链接功能会使用有些请求得不到响应;
折衷:使用较短的持久链接时间;
httpd-2.4 支持毫秒级持久时间;
非持久链接
KeepAlive On|Off
MaxKeepAliveRequests #
KeepAliveTimeout #
测试:
telnet HOST PORT
GET /URL HTTP/1.1
Host:HOSTNAME or IP
三、MPM
Multipath Process Module:多道处理模块
prefork,worker,event
httpd-2.2不支持同时编译多个模块,因此只能编译时选定一个;rpm安装的包提供三个二进制程序文件,分别用于实现对不一样MPM支持:确认方法:
# ps aux | grep httpd
默认为/usr/sbin/httpd,其使用prefork
查看模块列表:
查看静态编译的模块
# httpd -l
Compiled in modules:
core.c
prefork.c
http_core.c
mod_so.c
查看静态编译及动态装载的模块
# httpd -M
更换使用的httpd程序:
/etc/sysconfig/httpd
HTTPD=
重启服务生效:
prefork的配置:
worker的配置:
PV,UV
PV:Page View
UV:User View
独立IP量:
300*86500=40W+
四、DSO
配置指令实现模块加载
LoadModule <mod_name> <mod_path>
模块路径可以使用相对地址
相对于ServerRoot(/etc/httpd)指向的路径而言;
/etc/httpd/modules/
五、定义'Main' server的文档页面路径
DocumnetRoot
文档路径映射:
DocumentRoot指赂的路径为URL路径的起始位置;
DocumentRoot "/var/www/html"
test/index.html --> http://HOST:PORT/test/index.html
六、站点访问控制
可基于两种类型的路径指明对哪些资源进行访问控制
文件系统路径:
<Directory " "> </Directory>
<File " "> </File>
<FileMatch " " > </FileMatch>
URL路径:
<Location " "> </Location>
...
访问控制机制:
基于来源地址;
基于帐号;
七、Directory中”基于来源地址“实现访问控制
(1) Options
全部可用特性:Indexes Includes FollowSymLinks SymLkinksifOwneratch ExecCGI MultiViews
None All
Indexes:索引;
FollowSymlinks:容许跟踪符号连接文件;
(2) 基于来源地址的访问控制机制
Order:检查次序
Order allow,deny
Order deny,allow
Allow from
Deny from
八、定义默认主页面
DirectoryIndex index.html index.html.var
九、日志设置
错误日志:
ErrorLog logs/error_log
LogLevel warn
debug, info, notice, warn, error, crit
访问日志:
CustomLog logs/access_log combined
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
%h:客户端IP地址;
%l:Remote logname (from identd, if supplied),-表示为空;
%u:Remote user (from auth; may be bogus if return status (%s
) is 401);
%t:Time the request was received (standard english format),服务器收到请求的时间;
%r:First line of request,请求报文的首行信息(method url version);
%>s:响应状态码;
%b:响应报文的大小,单位是字节,不包括响应报文首部;
%{Referer}i:请求报文当中“referer”首部的值;当前资源的访问入口,即从哪一个页面中的超连接跳转而来;
%{User-agent}i:请求报文当中“User-agent”首部的值;即发出请求用到的应用程序;
详情:http://httpd.apache.org/docs/2.2/mod/mod_log_config.html#formats
十、路径别名
DocumentRoot "/www/htdocs"
http://www.magedu.com/download/bash-4.4.2-3.e16.x86_64.rpm
--> /www/htdocs/download/bash-4.4.2-3.e16.x86_64.rpm
Alias /URL/ "/PATH/TO/SOMEDIR"
Alias /bbs/ "/forum/htdocs"
http://www.magedu.com/bbs/index.html
--> /forum/htdocs/bbs
十一、设定默认字符集
AddDefaultCharset UTF-U
GBK,GB2312,GB18030
十二、基于用户的访问控制
认证质询:
WWW-Authenticate:响应码为401,拒绝客户端请求,并说明要求客户提供帐号和密码;
认证:
Authorization:客户端用户填入帐号和密码后再次发送请求报文;认证经过,则服务器发送响应的资源;
认证类型:
basic:明文
digest:消息摘要
安全域:须要用户认证后方能访问的路径;
应该经过名称对其进行标识,并用于告知用户认证的缘由;
用户的帐号和密码存储于何处?
虚拟帐号:仅用于访问某服务时用到的认证标识;
存储:
文本文件
SQL数据库
ldap
nis
basic认证:
(1) 定义安全域
<Directory "/www/htdocs/admin">
Options None
AllowOverride None
AuthType Basic
AuthName "Administrator home"
AuthUserFile "/etc/httpd/conf.d/.htpasswd"
Require user tom jerry
</Directory>
容许帐号文件中的全部用户登陆访问;
Require valid-user
(2) 提供帐号和密码存储(文本文件)
使用htpasswd命令进行管理
htpasswd [options] passwordfile username
-c:自动建立passwordfile,所以,仅应该在添加第一用户时使用;
-m:md5加密用户密码;
-s:sha1加密用户密码;
-D:删除指定用户
(3) 实现基于组进行认证
<Directory "/www/htdocs/admin">
Options None
AllowOverride None
AuthType Basic
AuthName "Administrator home"
AuthUserFile "/etc/httpd/conf.d/.htpasswd"
AuthGroupFile "/etc/httpd/conf.d/.htgroup"
Require group GROUP1 GROUP2 ...
</Directory>
要提供:用户帐号文件和组文件;
组文件:每一行定义一个组
GRP_NAME:user1 user2 user3
1三、虚拟主机
有三种实现方案:
基于ip:
为每一个虚拟主机准备至少一个ip地址;
基于port:
为每一个虚拟主机准备至少 一个专用port;实践中不多使用;
基于hostname:
为每一个虚拟主机作准备至少 一个专用hostname;
可混合使用上述三种方式中任意方式;
注意:通常虚拟主机莫与中心主机混用,因此,要使用虚拟主机,先禁用中心主机;
禁用中心主机:注释DocumnetRoot
每一个虚拟主机都有专用配置:
<VirtualHost IP:PORT> #这个IP和PORT即为虚拟主机监听的套接字,这个套接字在全局Listen也要被定义。
SeverName
DocumnetRoot " "
</VirtualHost>
SeverAlias:虚拟主机的别名;
ErrorLog
CustomLog
<Directory "">
</Directory>
示例1:基于ip
<VirtualHost 192.168.6.129:80>
DocumentRoot /vhost/web1/htdocs
ServerName web1.magedu.com
</VirtualHost>
<VirtualHost 192.168.6.130:80>
DocumentRoot /vhost/web2/htdocs
ServerName web2.magedu.com
</VirtualHost>
示例2:基本port
<VirtualHost 192.168.6.130:80>
DocumentRoot /vhost/web2/htdocs
ServerName web2.magedu.com
</VirtualHost>
<VirtualHost 192.168.6.130:8080>
DocumentRoot /vhost/web3/htdocs
ServerName web3.magedu.com
</VirtualHost>
示例3:基于hostname # 须要开启NameVirtualHost 192.168.6.129:80
<VirtualHost 192.168.6.129:80>
DocumentRoot /vhost/web1/htdocs
ServerName web1.magedu.com
</VirtualHost>
<VirtualHost 192.168.6.129:80>
DocumentRoot /vhost/web2/htdocs
ServerName web2.magedu.com
</VirtualHost>
<VirtualHost 192.168.6.129:80>
DocumentRoot /vhost/web3/htdocs
ServerName web3.magedu.com
</VirtualHost>
1四、内置的status页面
<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all
Allow from 192.168
</Location>
实现:基于帐号实现访问控制
检查httpd的配置有没有错误:httpd -t 或 service httpd configtest