1、基本概念
Define SRVROOT "/Apache24" ServerRoot "${SRVROOT}" #Apache安装的根路径 #Listen 12.34.56.78:80 Listen 80 #Apache服务器监听的IP地址和端口,只写端口表示会监听这台服务器上所有的IP # LoadModule foo_module modules/mod_foo.so #动态加载模块,比如代理模块、PHP模块(这样才能识别PHP) #LoadModule access_compat_module modules/mod_access_compat.so LoadModule actions_module modules/mod_actions.so LoadModule alias_module modules/mod_alias.so LoadModule allowmethods_module modules/mod_allowmethods.so LoadModule asis_module modules/mod_asis.so ...... User daemon Group daemon #设置Apache在什么账户下运行,如果使用root登录则存在很大风险,用户组Group起到风险隔离 ServerAdmin admin@example.com #有些时候服务器出现故障时,需要服务器自动发邮件给管理员 ServerName localhost:80 #ServerName可以是机器名或IP,即localhost或127.0.0.1 <Directory /> AllowOverride none Require all denied </Directory> #设置接入的访问权限 DocumentRoot "${SRVROOT}/htdocs" #Apache服务器下面的网站默认路径是在htdoc,即只需要把PHP文件放在该文件夹下就能被Apache找到、识别并执行 <Directory "${SRVROOT}/htdocs"> ...... #具体路径以及权限设置和属性 <IfModule dir_module> DirectoryIndex index.html </IfModule> #如果不设置具体访问哪个文件,就会返回DirectoryIndex指定的网页,按顺序查找,比如index.html、index.php等 <Files ".ht*"> Require all denied </Files> #某一类或某一个文件的权限设置 ErrorLog "logs/error.log" #服务器出错的时候日志输出位置,这里不以/开头表示相对路径,即相对于ServerRoot而言的路径 LogLevel warn #日志输出级别的设置,开发的时候可以设置debug,这样调试信息丰富,但是文件产生的较多,实际应用时设置warm即可 <IfModule logio_module> # You need to enable mod_logio.c to use %I and %O LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i" %I %O" combinedio </IfModule> #日志文件输出格式 CustomLog "logs/access.log" common #自定义写log的路径 <Directory "${SRVROOT}/cgi-bin"> AllowOverride None Options None Require all granted </Directory> #规定cgi-bin路径下的权限设置 Include conf/extra/httpd-autoindex.conf #其他路径下的配置文件 <IfModule ssl_module> #Include conf/extra/httpd-ssl.conf Include conf/extra/httpd-ahssl.conf SSLRandomSeed startup builtin SSLRandomSeed connect builtin </IfModule> #SSL模块的配置属性
2、常见写法
(1)直接配置
ServerRoot "${SRVROOT}" Listen 80
(2)加载其他配置文件--Include
Include conf/extra/httpd-info.conf
(3)加载动态模块--LoadModule
LoadModule actions_module modules/mod_actions.so
(4)条件设置
<IfModule dir_module> DirectoryIndex index.html </IfModule> #只有定义了dir_module的时候才会执行DirectoryIndex #条件执行的还有IfDefine、IfModule等
(5)文件夹设置
<Directory /> AllowOverride none Require all denied </Directory> #Directory对某一个目录的文件夹进行设置,这里/表示对所有文件进行设置,也可设置某一个文件夹 <Files ".ht*"> Require all denied </Files> #对文件的权限进行设置,这里是指对后缀为ht的所有文件进行权限设置,Require all denied表示拒绝用户的请求,这里面包含的是password信息
3、常见配置
打开方式:conf文件夹下或XAMPP中点击configure
(1)httpd.conf是主要配置文件,还有其他的配置文件
(2)"/"开头表示绝对路径,其他的是相对路径,即相对于ServerRoot而言
(3)ServerName可以是localhost或127.0.0.1,XAMPP安装的不需要设置,直接自动设置为localhost
(4)ServerRoot表示配置选项或其他选项的根路径,便于后期设置相对路径