0
点赞
收藏
分享

微信扫一扫

​Apache httpd主要配置文件详解

安装和启动

yum install httpd -y;systemctl enable --now httpd
systemctl status httpd

httpd 相关文件

配置文件:
/etc/httpd/conf/httpd.conf 主配置文件
/etc/httpd/conf.d/*.conf 子配置文件
/etc/httpd/conf.d/conf.modules.d/ 模块加载的配置文件

检查配置语法:httpd -t 或 apache2 -t

服务单元文件:
/usr/lib/systemd/system/httpd.service

配置文件:/etc/sysconfig/httpd

服务控制和启动
systemctl enable|disable httpd.service
systemctl {start|stop|restart|status|reload} httpd.service
apachectl start|stop|restart|configtest
service httpd configtest

站点网页文档根目录:/var/www/html

模块文件路径:
/etc/httpd/modules
/usr/lib64/httpd/modules

主服务器程序文件:/usr/sbin/httpd

主进程文件: /etc/httpd/run/httpd.pid

日志文件目录:/var/log/httpd
access_log: 访问日志
error_log:错误日志
帮助文档包:httpd-manual

httpd.conf 主配置文件

vim /etc/httpd/conf/httpd.conf

ServerRoot "/etc/httpd" #用于指定Apache运行的根目录
Listen 80 #监听80端口
MaxClients 256 #指定同时能访问服务器的客户机数量为256
DocumentRoot "/var/www/html" #定义Main server的文档页面路径
#Alias /URL/ "/PATH/" #定义别名
DirectoryIndex index.html index.html.var #定义站点默认主页面文件
Include conf.d/*.conf #读取/etc/httpd/conf/conf.d/目录中所有以.conf结尾的文件
ServerName www.baidu.com #服务域名
ServerAdmin #设置管理员的邮箱
Include conf.d/*.conf #包含的子配置文件
User apache #用户是apache
Group apache #用户组是apache
Directory #认证授权和访问控制

##################################处理模块配置
<IfModule prefork.c> #当httpd服务使用的profork模型的时候:
StartServers 10 #默认启动10个作业进程
MinSpareServers 10 #空闲进程数不低于10个
MaxSpareServers 20 #空闲进程数最大20个
ServerLimit 256 #最多可以启动256个进程
MaxClients 256 #最大并发客户端数为256个
MaxRequestsPerChild 4000 #每个进程可以处理4000个请求,超过此数目进程被杀死并重新创建
</IfModule>

ServerLimit最大值为20000个,profork是单一线程的进程,每个进程在同一时间里仅能处理一个请求(也就是一个请求一个进程),MaxClients的值要和ServerLimit一致。

MPM 多路处理模块

httpd 支持三种MPM工作模式:prefork, worker, event,可以切换使用MPM:

vim /etc/httpd/conf.modules.d/00-mpm.conf

#启用要启用的MPM相关的LoadModule指令即可,其它未启用的两项需要在行首加#注释
#同时启用多个MPM模块,出现报错
#LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
#LoadModule mpm_worker_module modules/mod_mpm_worker.so
LoadModule mpm_event_module modules/mod_mpm_event.so

查看CentOS 8 默认的MPM工作模式

[root@centos8 ~]#httpd -M |grep mpm
AH00558: httpd: Could not reliably determine the server's fully qualified domain
name, using centos8.localdomain. Set the 'ServerName' directive globally to
suppress this message
mpm_event_module (shared) #本行

#查看CentOS 7 默认的MPM工作模式
[root@centos7 ~]#httpd -M |grep mpm
AH00558: httpd: Could not reliably determine the server's fully qualified domain
name, using centos7.localdomain. Set the 'ServerName' directive globally to
suppress this message
mpm_prefork_module (shared) #本行

prefork 模式相关的配置

StartServers 100
MinSpareServers 50
MaxSpareServers 80
ServerLimit 2560 #最多进程数,最大值 20000
MaxRequestWorkers 2560 #最大的并发连接数,默认256
MaxConnectionsPerChild 4000 #子进程最多能处理的请求数量。在处理MaxRequestsPerChild 个
请求之后,子进程将会被父进程终止,这时候子进程占用的内存就会释放(为0时永远不释放)
MaxRequestsPerChild 4000 #从 httpd.2.3.9开始被MaxConnectionsPerChild代替

worker和event 模式相关的配置

ServerLimit 16 #最多worker进程数 Upper limit on configurable number of
processes
StartServers 10 #Number of child server processes created at startup
MaxRequestWorkers 150 #Maximum number of connections that will be processed
simultaneously
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25 #Number of threads created by each child process


举报

相关推荐

0 条评论