[root@rhel6~]#vi/etc/httpd/conf/httpd.conf
###Section1:GlobalEnvironment
ServerRoot"/etc/httpd"#工作的根目录
KeepAliveOff#不使用长连接
MaxKeepAliveRequests100#最大请求次数
KeepAliveTimeout15#长连接使用时长
#MPM:MultiPathModules,在linux有三种模式
prefork:预先生成进程,一个请求用一个进程响应,稳定可靠,任何一个进程崩溃了不会影响其他进程,但性能比较差,尤其是在并发量比较大的情况下,消耗量比较多,涉及到大量的进程切换(默认使用的)。
worker:基于线程工作的,一个请求用一个线程响应,web服务器启动多个进程,每个进程生成多个线程。
event:基于事件处理模型的驱动,一个进程处理多个请求,是最强大的。
<IfModuleprefork.c>
StartServers8#服务启动的服务个数
MinSpareServers5#最小空闲进程数
MaxSpareServers20#最大空闲进程数
ServerLimit256#MaxClients的上限,若想调用MaxClients必须先调用这个选项
MaxClients256#最多同时允许多少连接数
MaxRequestsPerChild4000#最大响应次数,若超过该值,则直接kill掉
</IfModule>
<IfModuleworker.c>
StartServers4
MaxClients300
MinSpareThreads25
MaxSpareThreads75
ThreadsPerChild25#每个进程生成线程的数量
MaxRequestsPerChild0
</IfModule>
Listen80#监听所有IP的80端口,可同时监听多个端口
#Listen127.0.0.1:8080#只监听本地的8080端口
LoadModule...
Includeconf.d/*.conf#此目录下的所有.conf文件都是主配置文件的组成部分
Userapache
Groupapache
###Section2:'Main'serverconfiguration
ServerAdminroot@localhost#服务器管理员邮箱
ServerNamerhel6.vnimos.org:80#在虚拟主机中是必须的,否则会报错
UseCanonicalNameOff#正式名称
DocumentRoot"/var/www/html"#文档根目录
<Directory/>
OptionsFollowSymLinks#定义该目录下的所有网页文件访问选项(包含多个option)
FollowSymlinks允许访问符号链接指向的原文件
Indexes允许索引目录
MultiViews允许内容协商的多重视图
ExexCGI允许在该目录下执行CGI脚本
Includes允许服务器端包含的功能
IncludesNoexec允许服务器端包含的功能,但不能执行CGI脚本
All包含除MultiView之外的所有特性(如果没有options字段,则默认为ALL)
AllowOverrideNone
</Directory>
<Directory"/var/www/html">
OptionsIndexesFollowSymLinks
AllowOverrideNone#忽略.htaccess文件中的指令类型
AllowOverrideAll|None|directive-type[directive-type](directive-type包含AuthConfig、FileInfo、Indexes、Limit选项)
None:.htaccess文件将被完全忽略。
All:所有具有".htaccess"作用域的指令都允许出现在.htaccess文件中。
AuthConfig:允许使用与认证授权相关的指令(AuthDBMGroupFile,AuthDBMUserFile,AuthGroupFile,AuthName,AuthType,AuthUserFile,Require,等)
FileInfo:允许使用控制文档类型的指令、控制文档元数据的指令、mod_rewrite中的指令和mod_actions中的Action指令
Indexes:允许使用控制目录索引的指令
Limits:允许使用控制主机访问的指令(Allow,Deny,Order)
Orderallow,deny#访问控制(默认禁止所有用户访问)
#orderdeny,allow#访问控制(默认允许所有用户访问)
Allowfromall
</Directory>
<IfModulemod_userdir.c>
UserDirdisabled
</IfModule>
DirectoryIndexindex.htmlindex.html.var
AccessFileName.htaccess
###Section3:VirtualHosts#若配置了虚拟主机,则Section2里的配置无效(我们这里配置了虚拟主机,故无需看主服务配置的内容)
NameVirtualHost*:80#开启虚拟主机配置
<VirtualHost*:80>#配置基于域名的虚拟主机
DocumentRoot/var/www/server
ServerNameserver.vm.org
<Directory"/var/www/server">
Orderallow,deny
Allowfrom192.168.0.10#仅允许192.168.0.10的IP访问(其余的都禁止)
</Directory>
</VirtualHost>
<VirtualHost*:80>
DocumentRoot/var/www/html
ServerNamewww.vm.org
<Directory"/var/www/html">
AuthName"SecretPlace"#配置用户认证,认证时显示的名字
AuthTypebasic#基本认证类型
AuthUserFile/etc/httpd/htpasswd#认证用户账号密码文件
Requirevalid-user#只要有效的用户都能登陆
</Directory>
</VirtualHost>
<VirtualHost*:80>
DocumentRoot/var/www/access
ServerNameaccess.xfcy.org
<Directory"/var/www/access">
OptionsALL
AllowOverrideAuthConfig#配置基于.htaccess的用户登录认证
</Directory>
</VirtualHost>
[root@rhel6~]#mv/var/www/error/noindex.html./#移除该文件便于测试
[root@rhel6~]#cat/var/www/html/index.html
HelloThisiswww.vm.org
[root@rhel6~]#cat/var/www/server/index.html
HelloThisisserver.vm.org
[root@rhel6~]#cat/var/www/access/index.html
HelloThisisaccess.xfcy.org!
[root@rhel6~]#htpasswd-cm/etc/httpd/htpasswduser1#创建用户认证文件(首次创建需加-c选项)
Newpassword:
Re-typenewpassword:
Addingpasswordforuseruser1
[root@rhel6~]#htpasswd-m/etc/httpd/htpasswduser2#添加user2用户
Newpassword:
Re-typenewpassword:
Addingpasswordforuseruser2
[root@rhel6~]#vi/var/www/access/.htaccess#配置基于.htaccess的用户登录认证
Authname"secretplace"
AuthTypeBasic
AuthUserFile/var/www/access/htpasswd
Requirevalid-user
[root@rhel6~]#htpasswd-cm/var/www/access/htpasswduser3#创建用户认证文件
通过Windows系统访问测试需向"C:\Windows\System32\drivers\etc\hosts"文件添加以下内容:
192.168.0.90www.vm.org
192.168.0.90server.vm.org
192.168.0.90access.vm.org
同样,Linux系统如未配置DNS进行解析也需向/etc/hosts文件添加以上两行内容
转载于:https://blog.51cto.com/onlyoulinux/1301874