配置文件:
- /etc/httpd/conf/httpd.conf 主配置文件
- /etc/httpd/conf.d/*.conf 子配置文件
- /etc/httpd/conf.d/conf.modules.d/ 模块加载的配置文件
检查配置语法:httpd –t
模块文件路径:
- /etc/httpd/modules
- /usr/lib64/httpd/modules
默认站点网页文档根目录:
- /var/www/html
日志文件目录:
- /var/log/httpd/access_log访问日志
- /var/log/httpd/error_log错误日志
默认配置文件
[root@centos8 ~]#grep -Ev '^ *#|^$' /etc/httpd/conf/httpd.conf
ServerRoot "/etc/httpd" ##设置根目录,后面的/实际都是在/etc/httpd/下面
Listen 80 ##监听端口,可重复出现,默认监听本机所有IP,可指定监听本机特定IP,例:192.168.1.100:8080
Include conf.modules.d/*.conf ##包含加载模块配置目录
User apache ##运行httpd的用户
Group apache ##运行httpd的组
ServerAdmin root@localhost
<Directory />
AllowOverride none
Require all denied
</Directory>
DocumentRoot "/var/www/html" ##指向的路径为URL路径的起始位置
<Directory "/var/www"> ##/path 必须显式授权后才可以访问
AllowOverride None
Require all granted ##所有访问授权
</Directory>
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<IfModule dir_module>
DirectoryIndex index.html ##定义站点主页面,可加如:index.htm index.php(需安装PHP模块)
##如访问www.yunmix.top和www.yunmix.top/index.html是一样
</IfModule>
<Files ".ht*">
Require all denied
</Files>
ErrorLog "logs/error_log"
LogLevel warn
<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" combined ##使用上述日志格式
</IfModule>
<IfModule alias_module> ##定义路径别名
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
</IfModule>
<Directory "/var/www/cgi-bin">
AllowOverride None
Options None
Require all granted
</Directory>
<IfModule mime_module>
TypesConfig /etc/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
</IfModule>
AddDefaultCharset UTF-8 ##设定默认字符集
<IfModule mime_magic_module>
MIMEMagicFile conf/magic
</IfModule>
EnableSendfile on
IncludeOptional conf.d/*.conf ##包含子配置文件