httpd配置文件详解
#vim /etc/etc/httpd/conf/httpd.conf
1、监听套接字
Listen [IP:]port
此指令可以出现多次, 用于指定监听多个不同的套接字:
Listen 80
Listen 172.16.100.7:8080

2、 配置使用keep alive(生存活跃时间)
KeepAlive {On|Off}
KeepAliveTimeout 2
MaxKeepAliveRequests 50

3、 MPM
<IfModule prefork.c>
StartServers: 默认启动的工作进程数;
MinSpareServers: 最少空闲进程数;
MaxSpareServers: 最大空闲进程数;
ServerLimit: 最大活动进程数;
MaxClients: 并发请求的最大数;
MaxRequestsPerChild: 每个子进程在生命周期内所能够服务的最多请求个数;

</IfModule>
<IfModule worker.c>
StartServers:启动的子进程的个数
MaxClients: 并发请求的最大数;
MinSpareThreads:最小空闲线程数;
MaxSpareThreads:最大空闲线程数;
ThreadsPerChild:每个子进程可生成的线程数;
MaxRequestsPerChild:每个子进程在生命周期内所能够服务的最多请求个数,0表示不限定;
</IfModule>

4、DSO模块加载方式
LoadModule module_name /path/to/module
如果使用相对路径,则对于ServerRoot所定义的位置而言;例如:
LoadModule php5_module /usr/lib64/httpd/modules/php5.so
让服务重载配置文件方能生效;
httpd -M: 列出已经装载的所有DSO及非DSO模块
httpd -l: 列出支持使用的非DSO模块

5、 配置站点根补录

6 配置网页访问属性
<Direcotry "/path/to/somewhere">
Options:
Indexes: 缺少指定的默认页面时,允许将目录中的所有文件以列表形式返回给用户;危险;
FollowSymLinks: 允许跟随符号链接所指向的原始文件;
None: 所有都启用;
All: 所有都启用;
ExecCGI: 允许使用mod_cgi模块执行CGI脚本;
Includes: 允许使用mod_include模块实现服务器端包含(SSI);
MultiViews:允许使用mod_negotiation实现内容协商;
SymLinksIfOwnerMatch:在链接文件属主属组与原始文件的属主属组相同时,允许跟随符号链接所指向 的原始文件;
<Directory>

7、 基于主机的访问控制
<Direcotry "/path/to/somewhere">
Options
AllowOverride None
Order Deny,Allow
Allow
Deny
<Directory>
最佳匹配:从列表中找出最小的能匹配到访问者的地址的条目为最终生效的;
Allow from
Deny from
IP, Network Address
172.16
172.16.0.0
172.16.0.0/16
172.16.0.0/255.255.0.0

8、 定义默认主页面
DirectoryIndex index.php index.html home.html default.html

9、用户目录
如果期望让每个用户都可以创建个人站点:http://Server_IP/~Username/
userdir disabled: 禁止
userdir public_html
public_html是用户家目录下的目录名称,所有位于此目录中的文件均可通过前述的访问路径进行访问
用户的家目录得赋予运行httpd进程的用户拥有执行权限;

10、配置日志功能
/var/log/httpd/
access.log: 访问日志,其需要记录的内容需要自定义
error.log: 错误日志
访问日志:
CustomLog "/path/to/access_log_file" Format_Name
LogFormat Format_String Format_Name
%h: 客户端地址
%l: 远程登录名,通常为-
%u: 认证时的远程用户名,没有认证时为-
%t: 收到请求时的时间;
%r: 请求报文的起始行;
%>s: 响应状态码;
%b: 响应报文的长度,单位为字节
%{Header_Name}i: 记录指定请求报文首部的内容(value);

11、 路径别名
Alias /alias/ "/path/to/somewhere"
意味着访问http://Server_IP/alias/时,其页面文件来自于/path/to/somewhere这个位置;

12、设置默认字符集
AddDefaultCharset

13、CGI脚本路径别名
CGI路径 /var/www/cgi-bin
URL --> FileSystem Directory
CGI: Common Gateway Interface协议
Content-Type: text/html 文本类型为text/html
14、 基于用户的访问控制
虚拟用户:
文件:/etc/httpd/conf/.htpasswd
认证类型(auth):
basic: 基本认证,帐号和密码明文发送;
digest:摘要认证,hash编程之后发送;
认证提供者(authentication provider):帐号和密码的存放位置
authn
授权机制(authorization):根据什么进行授权
15、虚拟主机
一个物理服务器提供多个站点; 使用虚拟主机得先取消中心主机
Web: Socket(IP, port)
基于不同的IP实现不同的虚拟主机
变化IP
基于不同的port实现不同的虚拟主机
变化port
基于不同的FQDN实现不同的虚拟主机
变化ServerName的值
NameVirtualHost *:80
<virtualhost IP:port>
ServerName
DocumentRoot ""
<Directory "">
Options
</Directory>
ServerAlias
ServerAdmin
</virtualhost>
虚拟主机的单独配置:
用户认证
访问日志
错误日志
别名
脚本别名
=======================未完==============================================
PS:后续还有
本文出自 “西风瘦猪” 博客,请务必保留此出处http://jungege.blog.51cto.com/4102814/1379733
httpd协议详解(二),布布扣,bubuko.com
httpd协议详解(二)
原文:http://jungege.blog.51cto.com/4102814/1379733