源码安装Apache配置文件解析
vim /usr/local/apache2/conf/httpd.conf
ServerRoot "/usr/local/apache2" Apache的安装路径
Listen 12.34.56.78:80 #监听网卡的端口,只允许12.34.56.78:50这个网卡的80端口访问,默认注释掉
Listen 80 #默认开启,监听所有网卡的80端口
Dynamic Shared Object (DSO) Support #动态共享对象,,下边这些都是模块,需要的时候打开注释加载模块,例如,如果需要使用虚拟主机,则需要打开相应的动态共享对象
LoadModule authn_file_module modules/mod_authn_file.so
#LoadModule authn_dbm_module modules/mod_authn_dbm.so
LoadModule authn_core_module modules/mod_authn_core.so
LoadModule authz_host_module modules/mod_authz_host.so
#LoadModule vhost_alias_module modules/mod_vhost_alias.so
# Virtual hosts
#Include conf/extra/httpd-vhosts.conf #设置虚拟主机的时候需要打开注释,会调用conf/extra/httpd-vhosts.conf这个文件,且需要打开vhost的动态共享对象,其他设置同理
<IfModule unixd_module> #用户名和用户组,一般都修改为Apache
User daemon #用户名
Group daemon #用户组
</IfModule>
ServerAdmin you@example.com #指定Apache的管理员邮箱地址
ServerName www.example.com:80 #指定Apache的域名
<Directory /> #区域声明,声明操作系统/区域
AllowOverride none #特殊权限开关,不允许做任何特殊权限设置,默认为none ,开启为all
Require all denied #默认不允许访问,开启为granted
</Directory>
DocumentRoot "/usr/local/apache2/htdocs" #定义网站的根目录
<Directory "/usr/local/apache2/htdocs"> #区域声明
Options Indexes FollowSymLinks # Indexes 存在时,网页丢失会显示当前目录的所有内容,不安全,一般情况不允许访问其他文件及目录,Indexes关闭时(删除此选项),网页文件丢失,就不允许用户访问服务器
# FollowSymLinks 允许链接文件充当网页,不允许则删除即可
AllowOverride None #是否允许有其他权限设置,默认none,不允许
Require all granted #允许所有用户访问
</Directory>
<IfModule dir_module> #网站根目录的默认网页声明
DirectoryIndex index.html #指定主页文件,用户使用的页面,可以是一个,也可以是多个,当第一个丢失,就会启用第二个,以此类推
</IfModule>
<Files ".ht*"> #.ht*开头的文件,一般都是拥有特权的文件
Require all denied #不允许访问
</Files>
ErrorLog "logs/error_log" #错误日志存放路径,这里用的是相对路径
LogLevel warn #记录错误日志的等级,错误日志分为6级,分别为debug info notice warn error crit,生产环境一般为5或6级
<IfModule log_config_module> #日志声明区域
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined #日志格式 日志记录的内容 声明格式的名称
LogFormat "%h %l %u %t \"%r\" %>s %b" common
<IfModule logio_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>
CustomLog "logs/access_log" common #访问日志所用日志的名称为conmmon
</IfModule>
<IfModule alias_module>
ScriptAlias /cgi-bin/ "/usr/local/apache2/cgi-bin/"
</IfModule>
<IfModule alias_module> #别名声明区域
ScriptAlias /cgi-bin/ "/usr/local/apache2/cgi-bin/"
alias "/a" "/usr/local/apache2/htdocs/a/b/c/d" #声明别名
</IfModule
<IfModule mime_module> #解析文件类型声明,遇到什么类型的文件,交给谁处理
TypesConfig conf/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz #能够解析的文件类型,如果没有需要解析的类型得添加
</IfModule>