Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@yangfch3
Last active May 18, 2017 04:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yangfch3/b78bc7aa492a39beea5308deb885a459 to your computer and use it in GitHub Desktop.
Save yangfch3/b78bc7aa492a39beea5308deb885a459 to your computer and use it in GitHub Desktop.
(macOS) httpd 系列配置文件注解翻译
# extra/httpd-default.conf
# 这个配置文件展示 Apache HTTP Server 的默认设置
#
# 你可能变更这些,但是一般情况下你并不需要更改
# Timeout:收发超时前的秒数
Timeout 60
# KeepAlive:是否允许持续连接(每个连接可以有多次请求)—— 即不立即分手
# 设置为 "off" 关闭
#
KeepAlive On
# MaxKeepAliveRequests:长连接期间允许的最大请求数
# 设为 0 表示允许无限数量
# 为了有更好的性能,我们推荐你设置一个较大值
MaxKeepAliveRequests 100
# KeepAliveTimeout:等待下个使用相同连接、来自同一个客户端请求的秒数
KeepAliveTimeout 5
# UseCanonicalName:决定 Apache 服务器如何构建自引用 URLs、SERVER_NAME
# 和 SERVER_ROOT 变量。当设置为 "off",Apache 将使用 Hostname
# 和端口为客户端提供服务。当设置为 "On",Apache 将使用 SeverName 指令的值
UseCanonicalName Off
# AccessFileName:在每一个目录下用于查找额外配置指令的文件名称
# 又见 AllowOverride 指令
AccessFileName .htaccess
# ServerTokens
# 这个指令配置你做为 HTTP 服务器 Response Header 系统信息返回值
# 默认值为 "Full",会传送编译在模块里的操作系统类型信息
# 从下列值选其一: Full | OS | Minor | Minimal | Major | Prod
# Full 会传送最多信息,Prod 选项传送最少
ServerTokens Full
# 可选地添加包含服务器版本和虚拟主机名的一行,用于服务器生成页面
# (内部错误文档、FTP 目录列表、mod_status 和 mod_info 输出等,
# 但不包括 CGI 生成文档或自定义错误文档)
# 设置为 "EMail" 也需要一个邮件地址:地址指向 ServerAdmin 指令。
# 可选值: On | Off | EMail
ServerSignature Off
# HostnameLookups:记录客户端的名字或 IP 地址
# 例如:www.apache.org (开启时) or 204.62.129.132 (关闭时)。
# 默认值为 off,如果我们不需要特异地打开这个开关的话,网络情况总体上来说会更好
# 因为开启他意味着每个客户端请求将会导致至少向域名服务器发起一次查询
HostnameLookups Off
# 为客户端花费多久以发送请求头和主体设置一个定时器
# 请求头的默认值是:header=20-40,MinRate=500,这意味着等待 headers 首字节
# 持续 20s。如果一些数据到达,将增加对应于 500字节/秒 的数据速率的超时,但不超过40秒。
#
# 请求主体的默认值为:body=20,MinRate=500,这与上文的请求头配置相似,但是
# 不为定时器设置上限
# 禁用则设置为 header=0 body=0
<IfModule reqtimeout_module>
RequestReadTimeout header=20-40,MinRate=500 body=20,MinRate=500
</IfModule>
# Server-Pool Management (MPM specific)
# PidFile:当服务器启动时记录其进程 ID 的文件
# (记录httpd守护进程的pid号码,这是系统识别一个进程的方法,
# 系统中httpd进程可以有多个,但这个PID对应的进程是其他的父进程)
#
# 注意:对于大多数 MPMs 来说这是默认 PidFile
<IfModule !mpm_netware_module>
PidFile "/private/var/run/httpd.pid"
</IfModule>
# 只有下面块中的某个将会与你已安装的 httpd 相关,使用 "apachectl -l" 招出激活的 mpm
# prefork MPM
# StartServers: 启动的服务器进程数量
# MinSpareServers: 闲置服务器进程的最小值
# MaxSpareServers: 闲置服务器进程的最大值
# MaxRequestWorkers: 允许启动的服务器进程的最大值
# MaxConnectionsPerChild: 一个服务器进程在终止前能服务的连接的最大值
<IfModule mpm_prefork_module>
StartServers 1
MinSpareServers 1
MaxSpareServers 10
MaxRequestWorkers 250
MaxConnectionsPerChild 0
</IfModule>
# worker MPM
# StartServers: 启动的服务器进程的初始化数量
# MinSpareThreads: 闲置工作线程的最小值
# MaxSpareThreads: 闲置工作线程的最大值
# ThreadsPerChild: 每个服务器进程下工作线程的常量
# MaxRequestWorkers: 工作线程的最大值
# MaxConnectionsPerChild: 一个服务器进程在终结之前服务的连接的最大值
<IfModule mpm_worker_module>
StartServers 3
MinSpareThreads 75
MaxSpareThreads 250
ThreadsPerChild 25
MaxRequestWorkers 400
MaxConnectionsPerChild 0
</IfModule>
# event MPM
# StartServers: 启动的服务器进程的初始化数量
# MinSpareThreads: 闲置工作线程的最小值
# MaxSpareThreads: 闲置工作线程的最大值
# ThreadsPerChild: 每个服务器进程下工作线程的常量
# MaxRequestWorkers: 工作线程的最大值
# MaxConnectionsPerChild: 一个服务器进程在终结之前服务的连接的最大值
<IfModule mpm_event_module>
StartServers 3
MinSpareThreads 75
MaxSpareThreads 250
ThreadsPerChild 25
MaxRequestWorkers 400
MaxConnectionsPerChild 0
</IfModule>
# NetWare MPM
# ThreadStackSize: 为每个工作线程分配的栈的大小
# StartThreads: 服务器启动时创建的工作线程的数量
# MinSpareThreads: 闲置线程的最小值,用于处理请求封
# MaxSpareThreads: 闲置线程的最大值
# MaxThreads: 同一时刻存活的工作线程的最大值
# MaxConnectionsPerChild: 一个线程服务的最大连接数,对于 NetWare 的这个指令推荐设置为默认值 0。
# 这允许进程持续地服务于请求
<IfModule mpm_netware_module>
ThreadStackSize 65536
StartThreads 250
MinSpareThreads 25
MaxSpareThreads 250
MaxThreads 1000
MaxConnectionsPerChild 0
</IfModule>
# OS/2 MPM
# StartServers: 维持的服务器进程数量
# MinSpareThreads: 每个进程闲置线程的最小值,用于处理请求峰
# MaxSpareThreads: 每个进程限制线程的最大值
# MaxConnectionsPerChild: 每隔服务器进程连接的最大值
<IfModule mpm_mpmt_os2_module>
StartServers 2
MinSpareThreads 5
MaxSpareThreads 10
MaxConnectionsPerChild 0
</IfModule>
# WinNT MPM
# ThreadsPerChild: 服务器进程下工作线程的常量
# MaxConnectionsPerChild: 一个服务器进程服务的连接的最大值
<IfModule mpm_winnt_module>
ThreadsPerChild 150
MaxConnectionsPerChild 0
</IfModule>
# 允许每个分配器(allocator)在不调用 free() 的情况下占用的自由 Kb 的最大值
# 在线程化的 MPMs 中,每一个线程都有它自己的分配器(allocator)
# 当没有设置或设置为 0 时,下限将被设为 unlimited
<IfModule !mpm_netware_module>
MaxMemFree 2048
</IfModule>
<IfModule mpm_netware_module>
MaxMemFree 100
</IfModule>
# Virtual Hosts
#
# 所需模块:mod_log_config
# 如果你想在你的机器上运行多个域名/主机名,你可以为这些域名/主机名设置 <VirtualHost> 块。
# 大多数配置使用基于名称的虚拟主机,所以服务器不需要担心多个 IP 地址
# 这在下面的指令中通过 * 表征
#
# 在视图配置虚拟主机前可深入阅读文档 http://httpd.apache.org/docs/2.4/vhosts/
# 你可以使用 "-S" 命令行选项来指定你的虚拟主机配置
# <VirtualHost> 实例:
# 几乎任何 Apache 指令能在 <VirtualHost> 块中使用。
# 第一个 <VirtualHost> 块用于无法与其他 <VirtualHost> 块的 ServerName
# 和 ServerAlias 匹配的所有请求
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "/usr/docs/dummy-host.example.com"
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog "/private/var/log/apache2/dummy-host.example.com-error_log"
CustomLog "/private/var/log/apache2/dummy-host.example.com-access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "/usr/docs/dummy-host2.example.com"
ServerName dummy-host2.example.com
ErrorLog "/private/var/log/apache2/dummy-host2.example.com-error_log"
CustomLog "/private/var/log/apache2/dummy-host2.example.com-access_log" common
</VirtualHost>
# 这是 Apache 服务器的主配置文件,它介绍了服务器接受的配置命令的说明。
#
# 查阅指令的详细信息见 http://httpd.apache.org/docs/2.4/
# 更进一步,你可以在 http://httpd.apache.org/docs/2.4/mod/directives.html
# 对每一个配置命令进行讨论
# 不要简单的阅读介绍而不去理解它们是做什么的,介绍(注释部分)在这里只作为指引和提醒
# 敬告:如果你不确定,请参阅在线文档
# 配置与日志文件名:如果你指定的文件名以 "/"(或者在 Win32 下以 "drive:/")开头
# 那么服务器将使用绝对路径。如果文件名不是以 "/"(或者在 Win32 下以 "drive:/")开头
# 那么 ServerRoot 将添加到给定路径的前面。
#
# 即:"logs/access_log" 将会根据 ServerRoot 被 Apache2 视为 "${ServerRoot}/logs/access_log"
# 而 "/logs/access_log" 则被简单地视为 "/logs/access_log"
# 第一节:全局变量配置
# ServerRoot:服务器配置、错误和日志文件被保存的顶层目录,不要在 ServerRoot 目录的末尾处添加斜杠
#
# 如果你指定 ServerRoot 不位于本地磁盘,那么确保在 Mutex directive 指定一个本地磁盘(如果使用基于文件的互斥锁).
# 如果你想为多个 httpd 后台进程共享 ServerRoot,那么你至少需要变更 PidFile
ServerRoot "/usr"
# Mutex: Allows you to set the mutex mechanism and mutex file directory
# for individual mutexes, or change the global defaults
#
# Uncomment and change the directory if mutexes are file-based and the default
# mutex file directory is not on a local disk or is not appropriate for some
# other reason.
#
# Mutex default:/private/var/run
# 注意:允许你绑定 Apache 到特定的 IP 地址和/或端口替代默认的设置
# 又见:<VirtualHost> 指令部分。
#
# 变更下方 Listen 指令监听具体的 IP 地址,以防止 Apache 使用所有你机器绑定的 IP
#
# Listen 12.34.56.78:80
Listen 80
# 支持动态共享对象(DSO)
#
# 为了能够使用以 DSO 形式创建的模块的功能,你必须在这里放置相应的 `LoadModule` 命令
# 以便该模块包含的指令在它们被使用之前是切实可用的。
#
# 静态的已编译模块(使用 `httpd -l` 列出的)不需要在这里载入。
#
# 实例:
# LoadModule foo_module modules/mod_foo.so
#
LoadModule authn_file_module libexec/apache2/mod_authn_file.so
# LoadModule authn_dbm_module libexec/apache2/mod_authn_dbm.so
# ......(这里是载入的一系列模块)
# LoadModule hfs_apple_module libexec/apache2/mod_hfs_apple.so
<IfModule unixd_module>
#
# 如果你希望 httpd(apache2) 以不同的用户或用户组运行,你必须以 root 身份
# 初始运行 httpd,这样 httpd 才能切换。
#
# User/Group:运行 httpd 的用户/用户组的名称(或 #编号)
# 通常的好做法是创建一个专用的用户和用户组用于运行 httpd,正如大部分系统服务一样
#
User _www
Group _www
</IfModule>
# 第二节:主服务器配置
# 'Main' server configuration:主服务器配置
#
# 这一节里的指令设置 'main' 服务器使用到的值,响应所有
# 不是由 <VirtualHost> 指定处理的请求。这些值也为所有的 <VirtualHost> 块
# 默认提供,<VirtualHost> 块将在此文件稍后部分定义
#
# 所有的这些指令也会出现在 <VirtualHost> 块内,这种情况下这些默认设置将被
# 定义的虚拟主机复写
# ServerAdmin:你的地址 —— 服务器问题发送邮件的目的地址
# 这个地址出现在一些服务器生成的页面,例如错误文档。
# 实例:admin@your-domain.com
#
ServerAdmin you@example.com
# ServerName 提供用于识别服务器的域名和端口
# 这部分经常能自动决定,但是我们推荐你明确指定它以防止启动期间的问题
#
# 如果你的主机还没有一个已注册的 DNS 域名,那么在这里可以输入主机的 IP 地址
# ServerName www.example.com:80
# 你的服务器整体文件系统的拒绝访问权限设置
# 在后面的其他 <Directory> 块中,你必须明确地准许访问 web 内容目录
<Directory />
AllowOverride none
Require all denied
</Directory>
# 记住从这里开始,你必须明确地允许特定的功能特性被启用 —— 所以如果某些功能
# 没有如你预期的那样运转,确保在下面你已开启它。
# DocumentRoot:提供 Web 服务的目录。
# 默认情况下,所有请求将在这个目录下拿去,但是符号链接与短名称可以用于指向其他位置
DocumentRoot "/Library/WebServer/Documents"
<Directory "/Library/WebServer/Documents">
# Options 指令的可能值有:"None", "All" 或下列值的组合:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# 注意:"MultiViews" 必须被明确地指定 —— "Options All" 不涵括 "MultiViews" 给你
#
# Options 指令复杂而又重要,获取更多信息请参阅:http://httpd.apache.org/docs/2.4/mod/core.html#options
Options FollowSymLinks Multiviews
MultiviewsMatch Any
# AllowOverride 控制哪些指令将被放置到 .htaccess 文件(s)内
# 它的值可能是 "All", "None" 或以下关键字的任意组合:
# AllowOverride FileInfo AuthConfig Limit
AllowOverride None
# 控制谁能从此服务器获取东西
Require all granted
</Directory>
# DirectoryIndex:设置请求目录时的默认文档
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
# 下面这些行防止 .htaccess .htpasswd 这些文件被 Web 客户端浏览
<FilesMatch "^\.([Hh][Tt]|[Dd][Ss]_[Ss])">
Require all denied
</FilesMatch>
# Apple 特定文件系统保护
<Files "rsrc">
Require all denied
</Files>
<DirectoryMatch ".*\.\.namedfork">
Require all denied
</DirectoryMatch>
# ErrorLog: 错误日志文件的位置
# 如果你没有在一个 <VirtualHost> 块内指定 ErrorLog 指令,那么该虚拟主机
# 的错误信息将会在此记录。如果你确实为 <VirtualHost> 块定义了一个错误日志文件,
# 则那个虚拟主机的错误将会记录在那而非在这。
ErrorLog "/private/var/log/apache2/error_log"
# LogLevel:控制被记录为 error_log 的信息的数量
# 可选值包括:debug, info, notice, warn, error, crit, alert, emerg.
LogLevel warn
<IfModule log_config_module>
# 下列指令一些格式昵称,用于下文的 CustomLog 指令
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>
# 你需要允许 mod_logio.c 使用 %I and %O
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>
# 访问日志文件的位置与格式(Common Logfile Format)
# 如果你没有在 <VirtualHost> 块内定义任何访问日志文件,那么它们将被记录在这里
# 反之,如果你为每一个 <VirtualHost> 定义了访问日志文件,那么将会记录在那儿
# 而非这个文件
CustomLog "/private/var/log/apache2/access_log" common
# 如果你更喜欢含有 access, agent 和 referer 信息的日志文件
# (Combined Logfile Format) 你可以使用以下指令
# CustomLog "/private/var/log/apache2/access_log" combined
</IfModule>
<IfModule alias_module>
# Redirect:允许你告诉客户端,文档以前存在于你的服务器的命令空间,但是现在已不存在
# 客户端将会对新位置的文档发起一个新的请求
# 例如:
# Redirect permanent /foo http://www.example.com/bar
# Alias: 映射 web 路径到文件系统路径
# 可用于访问不在 DocumentRoot 下的内容
# 例如:
# Alias /webpath /full/filesystem/path
# 如果你在 `/webpath` 后面添加了 `/`, 那么服务器将需要它出现在 URL 中
# (如:https://github.com/yangfch3 与 https://github.com/yangfch3/ 的区别)
# 你也可能需要提供一个 <Directory> 块以允许对该文件系统路径的访问
# ScriptAlias: 指定哪个目录含有服务器脚本
# ScriptAlias 本质上与 Aliases 一样,但是目标目录里的文档被视为应用程序
# 并且当它被请求时将会被服务器运行,而不是像文档一样直接传送给客户端
# Alias 指令的尾部 `/` 规则同样适用于 ScriptAlias 指令
ScriptAliasMatch ^/cgi-bin/((?!(?i:webobjects)).*$) "/Library/WebServer/CGI-Executables/$1"
</IfModule>
<IfModule cgid_module>
# ScriptSock: 在线程服务器上,为 UNIX 指定路径
# socket 用于与 mod_cgid 的 CGI 守护进程交流
# Scriptsock cgisock
</IfModule>
# 如果你有配置 ScriptAliased 的话,"/Library/WebServer/CGI-Executables"
# 应当更换成相应的、确切存在的 ScriptAliased CGI 目录
<Directory "/Library/WebServer/CGI-Executables">
AllowOverride None
Options None
Require all granted
</Directory>
<IfModule headers_module>
# 避免将HTTP_PROXY环境传递到CGI上,或者任何具有延迟“httpoxy”缺陷的代理后端服务器。 “代理”请求头未由IANA列出,IETF 中为 undefined
# Avoid passing HTTP_PROXY environment to CGI's on this or any proxied
# backend servers which have lingering "httpoxy" defects.
# 'Proxy' request header is undefined by the IETF, not listed by IANA
RequestHeader unset Proxy early
</IfModule>
<IfModule mime_module>
# TypesConfig 指定包含从文件扩展名到 MIME 类型映射列表的文件
TypesConfig /private/etc/apache2/mime.types
# AddType 允许你添加 MIME 映射配置,或复写在 TypesConfig 指定文件
# 中定义的 MIME 配置
# AddType application/x-gzip .tgz
#
# AddEncoding 允许你快速通晓特定浏览器的解压缩信息
# 注意:并非所有浏览器都支持
#
# AddEncoding x-compress .Z
# AddEncoding x-gzip .gz .tgz
# 如果上面的 AddEncoding 指令被注释,那么你也许应该
# 定义那些扩展以指定媒体类型:
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
# AddHandler 允许你映射特定的文件扩展到处理程序(处理器):与文件类型无关的行为
# 这些规则可以在这里通过 AddHandler 构建到服务器
# 也能通过下文的 Action 指令添加规则(二选其一)
#
# 使用 ScriptAliased 目录之外的 CGI 脚本:
# (你也需要为 "Options" 指令添加 "ExecCGI" 值)
#
# AddHandler cgi-script .cgi
# For type maps (negotiated resources):
# AddHandler type-map var
# Filters 允许你在将其发送至客户端前处理其内容
#
# 解析服务器端包含(SSI)的 .shtml 文件:
# (你也需要为 "Options" 指令添加 "Includes" 值)
#
# AddType text/html .shtml
# AddOutputFilter INCLUDES .shtml
</IfModule>
# mod_mime_magic 模块允许服务器使用文件自身内容的各种线索(提示)来决定它的类型
# MIMEMagicFile 指令告诉 mod_mime_magic 模块线索定义的位置
#
# MIMEMagicFile /private/etc/apache2/magic
# 可以使用三种风格来自定义错误 responses
# 1) plain text 2) local redirects 3) external redirects
#
# 一些实例:
# ErrorDocument 500 "The server made a boo boo."
# ErrorDocument 404 /missing.html
# ErrorDocument 404 "/cgi-bin/missing_handler.pl"
# ErrorDocument 402 http://www.example.com/subscription_info.html
# MaxRanges:在返回全部资源前的/一个请求中的/队列最大值
# 或以下特殊值中的一个:'default', 'none', 'unlimited'
# 默认设置是接收 200 个队列
# MaxRanges unlimited
# EnableMMAP 和 EnableSendfile:在支持其的系统上,可以使用
# 内存映射(memory-mapping)或传送文件系统调用(sendfile syscall)
# 来传送文件。这通常能提高服务器的性能,但是当使用网络挂载文件系统进行服务,
# 或这些功能的支持在你的系统损坏或不可用
# 时必须被关闭
# 默认值: EnableMMAP On, EnableSendfile Off
#
# EnableMMAP off
# EnableSendfile on
TraceEnable off
# 补充配置
#
# /private/etc/apache2/extra/ 目录下的配置文件能被引入,以便添加额外的特性
# 或修改当前服务器默认的配置,当然不使用 Include 指令的话
# 你也可以简单的拷贝它们的内容到这里并在必要时进行修改
# Server-pool management (MPM specific)
Include /private/etc/apache2/extra/httpd-mpm.conf
# 多语言错误信息
# Include /private/etc/apache2/extra/httpd-multilang-errordoc.conf
# 服务器输出目录列表展示配置
Include /private/etc/apache2/extra/httpd-autoindex.conf
# 语言设置
# Include /private/etc/apache2/extra/httpd-languages.conf
# 用户主页目录
# Include /private/etc/apache2/extra/httpd-userdir.conf
# 实时请求与配置信息
# Include /private/etc/apache2/extra/httpd-info.conf
# 虚拟主机
# Include /private/etc/apache2/extra/httpd-vhosts.conf
# 本地 HTTP Server Manul 访问配置
# Include /private/etc/apache2/extra/httpd-manual.conf
# 分布式创作和版本控制 Distributed authoring and versioning (WebDAV)
# Include /private/etc/apache2/extra/httpd-dav.conf
# 各种默认设置:超时、最大连接数等
# Include /private/etc/apache2/extra/httpd-default.conf
# 配置 mod_proxy_html 模块以使之支持理解 HTML4/XHTML1
<IfModule proxy_html_module>
Include /private/etc/apache2/extra/proxy-html.conf
</IfModule>
# Secure (SSL/TLS) 连接
# Include /private/etc/apache2/extra/httpd-ssl.conf
#
# 注意:下列必不可少的东西必须存在以支持没有 /dev/random 相等物、
# 没有 SSL,但是有一个静态的、已编译好的 mod_ssl 的系统的开启
# (original) Note: The following must must be present to support
# starting without SSL on platforms with no /dev/random equivalent
# but a statically compiled-in mod_ssl.
#
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>
Include /private/etc/apache2/other/*.conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment