Apache2配置文件解读

每次碰到都不知道具体的作用,所以来分析一下

配置文件结构

apache2在启动的时候自动读取/etc/apache2/apache2.conf文件的配置信息,不同的配置项按功能分布在不同的文件中,然后被Include包含到apache2.conf这个主配置文件中,方便管理。就是说事实上apache2主配置文件只有一个,即apache2.conf,其他的都是被include进来的。
image

主文件配置内容

### Section 1: Global Environment
#ServerRoot:apache服务器根目录。主配置文件,日志都在该目录。
#注意路径结束时不要加斜杠,默认是/etc/apache2
#ServerRoot "/etc/apache2"

LockFile ${APACHE_LOCK_DIR}/accept.lock

#apache服务启动时在该文件记录进程ID号
# This needs to be set in /etc/apache2/envvars
PidFile ${APACHE_PID_FILE}

#连接超时,单位秒
Timeout 300

#是否允许持久连接
KeepAlive On

#持久连接时最大请求数
MaxKeepAliveRequests 100

KeepAliveTimeout 5


# prefork MPM
<IfModule mpm_prefork_module>
    StartServers          5
    MinSpareServers       5
    MaxSpareServers      10
    MaxClients          150
    MaxRequestsPerChild   0
</IfModule>


# worker MPM
<IfModule mpm_worker_module>
    StartServers        10
    ServerLimit         100
    MinSpareThreads     50
    MaxSpareThreads     200
    ThreadsPerChild     64
    MaxClients          6400
    MaxRequestsPerChild   0
</IfModule>

# event MPM
<IfModule mpm_event_module>
    StartServers          2
    MinSpareThreads      25
    MaxSpareThreads      75
    ThreadLimit          64
    ThreadsPerChild      25
    MaxClients          150
    MaxRequestsPerChild   0
</IfModule>

# These need to be set in /etc/apache2/envvars
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

#apache服务启动后在每个目录中查找后缀是.htaccess的文件,这些文件作为附加的配置
AccessFileName .htaccess
#下面几行防止.htaccess和.htpassword文件被web客户端访问
<Files ~ "^\.ht">
    Order allow,deny
    Deny from all
    Satisfy all
</Files>

#DefaultType是浏览器访问的MIME类型,设置为None,让浏览器自行解析
DefaultType None

# HostnameLookups: Log the names of clients or just their IP addresses
# e.g., www.apache.org (on) or 204.62.129.132 (off).
HostnameLookups Off

#错误日志文件目录,默认是配置在此,可在<VirtualHost>中重载
#日志文件取名时以'/'开头会造成冲突,不以'/'开头,会默认加上服务器根目录前缀
#比如"foo.log"会被加上ServerRoor目录"/etc/apache2"变成"/etc/apache2/foo.log"
ErrorLog ${APACHE_LOG_DIR}/error.log

#Log日志记录哪些信息,取值可以是: debug, info, notice, warn, error, crit,alert, emerg.
LogLevel warn

#导入模块配置文件
Include mods-enabled/*.load
Include mods-enabled/*.conf
#导入所有用户配置文件
Include httpd.conf
#导入端口监听配置文件
Include ports.conf


# The following directives define some format nicknames for use with
# a CustomLog directive (see below).
# If you are behind a reverse proxy, you might want to change %h into %{X-Forwarded-For}i
#
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

#拦截访问
<VirtualHost *:80>
<Directory /***>
    Options None FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all 
</Directory>
</VirtualHost>


#导入通用配置目录
Include conf.d/

#导入虚拟主机的配置
Include sites-enabled/

网站根目录配置文件

在sites-avaliabrary中

posted @ 2021-11-29 13:32  Aur0ra*  阅读(1425)  评论(0编辑  收藏  举报