Apache configuration file httpd.conf

Apache's main configuration file: /etc/httpd/conf/httpd.conf

The default site home directory: / var / www / html /

Apache server configuration information is all stored in the main configuration file /etc/httpd/conf/httpd.conf, the contents of this file is very large, with wc command statistics, a total of 1009 lines, most of which is a comment line beginning with # .

[root@justin ~]# wc -l /etc/httpd/conf/httpd.conf 

/etc/httpd/conf/httpd.conf 

[root@justin ~]#


Profile consists of three parts:

[root@justin ~]# grep '\<Section\>' /etc/httpd/conf/httpd.conf -n 

33:### Section 1: Global Environment 

245:### Section 2: 'Main' server configuration 

973:### Section 3: Virtual Hosts 

[root@justin ~]#


1) Global Environment --- global configuration environment, the decision Apache server global parameters

2) Main server configuration --- main service configuration, is equivalent to the default Apache Web site, our server if only one site, then you just here to configure it.

3) Virtual Hosts --- web hosting, web hosting Main Server can not coexist with the primary server, when the virtual host is enabled, you can not use the Main Server


--------------------------------------------------------------------------------

1)Global Environment

ServerTokens OS


Whether to display the name of the server operating system when the error page, ServerTokens Prod is not displayed

ServerRoot "/etc/httpd"


Apache is used to specify the directory operation, the service started automatically change the directory to the current directory, to use relative paths are behind all want this directory

PidFile run/httpd.pid


Recording pid number httpd daemon process which is a method of system identification, the system can have multiple httpd process, but the process is the PID corresponding to the other parent

Timeout 60


Server and client disconnection time

KeepAlive Off


Whether persistent connections (because each had three-way handshake connection, if the traffic is not recommended to open this, if the site is closed this visit than the larger is better), amended as: KeepAlive On Permits procedural Online

MaxKeepAliveRequests 100


It represents the maximum number of requests a connection

KeepAliveTimeout 15


Time before disconnection

<IfModule prefork.c> 

StartServers 8 

MinSpareServers    5 

MaxSpareServers  20 

ServerLimit      256 

MaxClients      256 

MaxRequestsPerChild  4000 

</IfModule>


The default module, represents the start of a process for each access (that is, when there is a connection to the public more time to process, at the same time only one access to services).

Start 8 process, minimum idle 5 process began when StartServer service, idle up to 20 process.

MaxClient the same time limit the client's maximum number of connection requests exceeds the queue waiting to enter.

The maximum allowable service MaxRequestsPerChild lifetime number of requests per process, 0 means never ends

<IfModule worker.c> 

StartServers 4 

MaxClients        300 

MinSpareThreads    25 

MaxSpareThreads    75 

ThreadsPerChild    25 

MaxRequestsPerChild  0 

</IfModule>


为Apache配置线程访问,即每对WEB服务访问启动一个线程,这样对内存占用率比较小。

ServerLimit服务器允许配置进程数的上限。

ThreadLimit每个子进程可能配置的线程上限

StartServers启动两个httpd进程,

MaxClients同时最多能发起250个访问,超过的要进入队列等待,其大小有ServerLimit和ThreadsPerChild的乘积决定

ThreadsPerChild每个子进程生存期间常驻执行线程数,子线程建立之后将不再增加

MaxRequestsPerChild每个进程启动的最大线程数,如达到限制数时进程将结束,如置为0则子线程永不结束

Listen 80


监听的端口,如有多块网卡,默认监听所有网卡

150 LoadModule auth_basic_module modules/mod_auth_basic.so 

...... 

LoadModule version_module modules/mod_version.so


启动时加载的模块 mod_access已经更名为mod_authz_host

Include conf.d/*.conf


加载的配置文件

User apache 

Group apache


启动服务后转换的身份,在启动服务时通常以root身份,然后转换身份,这样增加系统安全


2)Main server configuration

ServerAdmin root@localhost


管理员的邮箱

#ServerName www.example.com:80


默认是不需要指定的,服务器通过名字解析过程来获得自己的名字,但如果解析有问题(如反向解析不正确),或者没有DNS名字,也可以在这里指定IP地址,当这项不正确的时候服务器不能正常启动。前面启动Apache时候提示正在启动 httpd:httpd: apr_sockaddr_info_get() failed forjustin httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1forServerName,解决方法就是启动该项把www.example.com:80修改为自己的域名或者直接修改为localhost

285 UseCanonicalName Off


如果客户端提供了主机名和端口,Apache将会使用客户端提供的这些信息来构建自引用URL。这些值与用于实现基于域名的虚拟主机的值相同,并且对于同样的客户端可用。CGI变量SERVER_NAME和SERVER_PORT也会由客户端提供的值来构建

DocumentRoot "/var/www/html"


网页文件存放的目录

<Directory /> 

   Options FollowSymLinks 

   AllowOverride None 

</Directory>


对根目录的一个权限的设置

<Directory "/var/www/html"> 

   Options Indexes FollowSymLinks 

   AllowOverride None 

   Order allow,deny 

   Allow from all 

</Directory>


对/var/www/html目录的一个权限的设置,options中Indexes表示当网页不存在的时候允许索引显示目录中的文件,FollowSymLinks是否允许访问符号链接文件。有的选项有ExecCGI表是否使用CGI,如Options Includes ExecCGI FollowSymLinks表示允许服务器执行CGI及SSI,禁止列出目录。SymLinksOwnerMatch表示当符号链接的文件和目标文件为同一用户拥有时才允许访问。AllowOverrideNone表示不允许这个目录下的访问控制文件来改变这里的配置,这也意味着不用查看这个目录下的访问控制文件,修改为:AllowOverride All 表示允许.htaccess。Order对页面的访问控制顺序后面的一项是默认选项,如allow,deny则默认是deny,Allowfromall表示允许所有的用户,通过和上一项结合可以控制对网站的访问控制

<IfModule mod_userdir.c> 

   UserDir disabled 

</IfModule>


是否允许用户访问其家目录,默认是不允许

#<Directory /home/*/public_html> 

#    AllowOverride FileInfo AuthConfig Limit 

#    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec 

#    <Limit GET POST OPTIONS> 

#        Order allow,deny 

#        Allow from all 

#    </Limit> 

#    <LimitExcept GET POST OPTIONS> 

#        Order deny,allow 

#        Deny from all 

#    </LimitExcept> 

#</Directory>


如果允许访问用户的家目录中的网页文件,则取消以上注释,并对其中进行修改

DirectoryIndex index.html index.html.var


指定所要访问的主页的默认主页名字,默认首页文件名为index.html

AccessFileName .htaccess


定义每个目录下的访问控制文件名,缺省为.htaccess

<Files ~ "^\.ht"> 

   Order allow,deny 

   Deny from all 

   Satisfy All 

</Files>


控制不让web上的用户来查看.htpasswd和.htaccess这两个文件

TypesConfig /etc/mime.types


用于设置保存有不同MIME类型数据的文件名

DefaultType text/plain


默认的网页的类型

<IfModule mod_mime_magic.c> 

#  MIMEMagicFile /usr/share/magic.mime 

   MIMEMagicFile conf/magic

</IfModule>


指定判断文件真实MIME类型功能的模块

HostnameLookups Off


当打开此项功能时,在记录日志的时候同时记录主机名,这需要服务器来反向解析域名,增加了服务器的负载,通常不建议开启

#EnableMMAP off


是否允许内存映射:如果httpd在传送过程中需要读取一个文件的内容,它是否可以使用内存映射。如果为on表示如果操作系统支持的话,将使用内存映射。在一些多核处理器的系统上,这可能会降低性能,如果在挂载了NFS的DocumentRoot上如果开启此项功能,可能造成因为分段而造成httpd崩溃

#EnableSendfile off


这个指令控制httpd是否可以使用操作系统内核的sendfile支持来将文件发送到客户端。默认情况下,当处理一个请求并不需要访问文件内部的数据时(比如发送一个静态的文件内容),如果操作系统支持,Apache将使用sendfile将文件内容直接发送到客户端而并不读取文件

484 ErrorLog logs/error_log


错误日志存放的位置

LogLevel warn


Apache日志的级别

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined 

LogFormat "%h %l %u %t \"%r\" %>s %b" common 

LogFormat "%{Referer}i -> %U" referer 

LogFormat "%{User-agent}i" agent


定义了日志的格式,并用不同的代号表示

#CustomLog logs/access_log common 

CustomLog logs/access_log combined


说明日志记录的位置,这里面使用了相对路径,所以ServerRoot需要指出,日志位置就存放在/etc/httpd/logs

ServerSignature On


定义当客户请求的网页不存在,或者错误的时候是否提示apache的版本的一些信息

Alias /icons/ "/var/www/icons/"


定义一些不在DocumentRoot下的文件,而可以将其映射到网页根目录中,这也是访问其他目录的一种方法,但在声明的时候切记目录后面加”/”

<Directory "/var/www/icons"> 

   Options Indexes MultiViews FollowSymLinks 

   AllowOverride None 

   Order allow,deny 

   Allow from all 

</Directory>


定义对/var/www/icons/的权限,修改为 Options MultiViews FollowSymLinks表示不在浏览器上显示树状目录结构

<IfModule mod_dav_fs.c> 

   # Location of the WebDAV lock database. 

   DAVLockDB /var/lib/dav/lockdb

</IfModule>


对mod_dav_fs.c模块儿的管理

ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"


对CGI模块儿的的别名,与Alias相似。

<Directory "/var/www/cgi-bin"> 

   AllowOverride None 

   Options None 

   Order allow,deny 

   Allow from all 

</Directory>


对/var/www/cgi-bin文件夹的管理,方法同上


# Redirect old-URI new-URL


Redirect参数是用来重写URL的,当浏览器访问服务器上的一个已经不存在的资源的时候,服务器返回给浏览器新的URL,告诉浏览器从该URL中获取资源。这主要用于原来存在于服务器上的文档改变位置之后,又需要能够使用老URL能访问到原网页

IndexOptions FancyIndexing VersionSort NameWidth=* HTMLTable Charset=UTF-8 

AddIconByEncoding (CMP,/icons/compressed.gif) x-compress x-gzip

... 

IndexIgnore .??* *~ *# HEADER* README* RCS CVS *,v *,t


当一个HTTP请求的URL为一个目录的时候,服务器返回这个目录中的索引文件,如果目录中不存在索引文件,并且服务器有许可显示目录文件列表的时候,就会显示这个目录中的文件列表,为了使得这个文件列表能具有可理解性,而不仅仅是一个简单的列表,就需要前这些参数。如果使用了IndexOptionsFancyIndexing选项,可以让服务器针对不同的文件引用不同的图标。如果没有就使用DefaultIcon定义缺省图标。同样,使用AddDescription可以为不同类型的文档介入描述

AddLanguage ca .ca 

...... 

AddLanguage zh-TW .zh-tw


添加语言

LanguagePriority en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv zh-CN zh-TW


Apache支持的语言

AddDefaultCharset UTF-8


默认支持的语言

#AddType application/x-tar .tgz


支持的应用如果想支持对php的解析添加这样一行

#AddEncoding x-compress .Z 

#AddEncoding x-gzip .gz .tgz


支持对以.Z和.gz.tgz结尾的文件

AddType application/x-compress .Z 

AddType application/x-gzip .gz .tgz


添加对上述两种文件的应用

#AddHandler cgi-script .cgi


修改为:AddHandler cgi-script .cgi .pl 表示允许扩展名为.pl的CGI脚本运行

AddType text/html .shtml 

AddOutputFilter INCLUDES .shtml


添加动态处理类型为server-parsed由服务器预先分析网页内的标记,将标记改为正确的HTML标识

#ErrorDocument 404 /missing.html


当服务器出现404错误的时候,返回missing.html页面

Alias /error/ "/var/www/error/"


赋值别名

<IfModule mod_negotiation.c> 

<IfModule mod_include.c> 

   <Directory "/var/www/error"> 

       AllowOverride None 

       Options IncludesNoExec 

       AddOutputFilter Includes html 

       AddHandler type-map var 

       Order allow,deny 

       Allow from all 

       LanguagePriority en es de fr 

       ForceLanguagePriority Prefer Fallback 

   </Directory>


对/var/www/error网页的权限及操作

BrowserMatch "Mozilla/2" nokeepalive 

BrowserMatch "MSIE 4\.0b2;" nokeepalive downgrade-1.0 force-response-1.0 

BrowserMatch "RealPlayer 4\.0" force-response-1.0 

BrowserMatch "Java/1\.0" force-response-1.0 

BrowserMatch "JDK/1\.0" force-response-1.0 

.....


设置特殊的参数,以保证对老版本浏览器的兼容,并支持新浏览器的特性

3)Virtual Hosts

#NameVirtualHost *:80


如果启用虚拟主机的话,必须将前面的注释去掉,而且,第二部分的内容都可以出现在每个虚拟主机部分。

# VirtualHost example: 

#<VirtualHost *:80> 

#    ServerAdmin [email protected] 

#    DocumentRoot /www/docs/www.linuxidc.com 

#    ServerName www.linuxidc.com 

#    ErrorLog logs/www.linuxidc.com-error_log 

#    CustomLog logs/www.linuxidc.com-access_log common 

#</VirtualHost>


Guess you like

Origin blog.51cto.com/14451009/2443743