您的位置:首页 > 理论基础 > 计算机网络

centos apache配置文件httpd.conf

2012-05-22 09:51 531 查看
添加了一些注释,不对的还请大家指点。2012-05-22

### Section 1: Global Environment

ServerTokens OS
#仅告知用户端服务器的版本与作业系统而已,要需要更动它.

ServerRoot "/etc/httpd"
#服务器设定的最顶层目录,有点类似chroot,包括log,modules等等资料都应该要放置在这个目录下.(前提是没有设定绝对路径时)

PidFile run/httpd.pid
#放置PID的档案,可方便APACHE软件的管理.是有相对路径考虑serverroot的设定值,这个档案应该在/etc/httpd/run/httpd.pid

Timeout 120
#不论接收与传送,当持续连线等待超过120秒则此交连线就中断.一般来说在300秒左右即可.

KeepAlive on
#是否允许持续性的连线,也就是一个TCP连线可以具有多个档案资料的传送要求。例如网页内包含多人图像,那么这一次连线就会将所有的资料传送完,而不必每个图像都需要进行一次TCP连线,改为on较佳。

MaxKeepAliveRequests 100
#与上一个keepalive的设置有关,当keepalive设为on时,则这个数值可决定此次连线能够传输的最大传输数量。为了增进效能,可增大这个值,0表示不限制。

KeepAliveTimeout 15
#在允许keepalive的条件下,则这次连线在最后勤部一次传输后等待的延迟秒数。

<IfModule prefork.c>
StartServers 8
#启动httpd时,唤醒几个PID来处理服务器的意思。
MinSpareServers 5
#最小的默认使用PID数量
MaxSpareServers 20
#最大的默认使用PID数量
ServerLimit 256
#服务器的限制
MaxClients 256
#最多右以允许多少用户同时连线到服务器。
MaxRequestsPerChild 4000
#每个程度能够提供的最大传输次数要求,例如,如果一个使用者连上服务器后(一个process),想要求数百个网页,当他的要求数量超过此值时,此程序就会被丢弃,另外切换一个新程序,这个设定可以有效的控管每个process在系统上的存活时间。
</IfModule>

<IfModule worker.c>
StartServers 2
MaxClients 150
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 0
</IfModule>

#上面的prefork及worker其实是与服务器连线资源有关的设定,默认的项目对于一般小型网站来说已经够用了,如果流量较大,可以修改此值。设定的值越大,系统反应速度越快。
#worker模组占用的记忆体较小,对于流量较大的网站来说,是一个比较好的选择。prefork虽然占用记忆体较大,不过与worker差不多,并且prefork记忆体使用设计较为优秀,可以在很多无法提供debud的平台上面进行自我除错,所以默认的模组就是prefork这一个。
#apache到底是使用哪个模组呢,事实上centos将这两个模色光分别放到不同的执行档中,分别是:/usr/sbin/httpd和/usr/sbin/httpd.worker。可以去查阅/etc/sysconfig/httpd,就能知道apache使用的是哪个模组。也可以修改这个文件来让apache用不同的模组。系统默认使用

#Listen 12.34.56.78:80
Listen 80
#与监听界面有关,默认监听所有介面,也可以修改端口号.

# LoadModule foo_module modules/mod_foo.so
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule auth_digest_module modules/mod_auth_digest.so
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authn_alias_module modules/mod_authn_alias.so
LoadModule authn_anon_module modules/mod_authn_anon.so
LoadModule authn_dbm_module modules/mod_authn_dbm.so
LoadModule authn_default_module modules/mod_authn_default.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule authz_owner_module modules/mod_authz_owner.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_dbm_module modules/mod_authz_dbm.so
LoadModule authz_default_module modules/mod_authz_default.so
LoadModule ldap_module modules/mod_ldap.so
LoadModule authnz_ldap_module modules/mod_authnz_ldap.so
LoadModule include_module modules/mod_include.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule logio_module modules/mod_logio.so
LoadModule env_module modules/mod_env.so
LoadModule ext_filter_module modules/mod_ext_filter.so
LoadModule mime_magic_module modules/mod_mime_magic.so
LoadModule expires_module modules/mod_expires.so
LoadModule deflate_module modules/mod_deflate.so
LoadModule headers_module modules/mod_headers.so
LoadModule usertrack_module modules/mod_usertrack.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule mime_module modules/mod_mime.so
LoadModule dav_module modules/mod_dav.so
LoadModule status_module modules/mod_status.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule info_module modules/mod_info.so
LoadModule dav_fs_module modules/mod_dav_fs.so
LoadModule vhost_alias_module modules/mod_vhost_alias.so
LoadModule negotiation_module modules/mod_negotiation.so
LoadModule dir_module modules/mod_dir.so
LoadModule actions_module modules/mod_actions.so
LoadModule speling_module modules/mod_speling.so
LoadModule userdir_module modules/mod_userdir.so
LoadModule alias_module modules/mod_alias.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule cache_module modules/mod_cache.so
LoadModule suexec_module modules/mod_suexec.so
LoadModule disk_cache_module modules/mod_disk_cache.so
LoadModule file_cache_module modules/mod_file_cache.so
LoadModule mem_cache_module modules/mod_mem_cache.so
LoadModule cgi_module modules/mod_cgi.so
LoadModule version_module modules/mod_version.so
#LoadModule cern_meta_module modules/mod_cern_meta.so
#LoadModule asis_module modules/mod_asis.so
# Load config files from the config directory "/etc/httpd/conf.d".
#载入模组的设定项,APACHE提供很多有用的模组给我们使用了.

Include conf.d/*.conf
#因为有这一行,所以放置到/etc/httpd/conf.d/*.conf的设定都会被读入.

ExtendedStatus On
#开启服务器状态说明模组。便要先确定LoadModle status_modules/mod_status.so这个参数存在。

<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all
Allow from .example.com
Allow from 10.1.230.35
Allow from 127.0.0.1
</Location>
#这个参数结合上面的参数,可以实现查阅服务器的状态。用户输入http://IP/server-status即可查阅。不过,可查阅的用户端要限制严格一些。不要所有人都可查阅。

User apache
Group apache
#前面提到的presork,worker等模组所启动的process之拥有者与群组设定.这个值很重要,因为未来你提供的网页档案能不能被浏览都与这个身份有关.

### Section 2: 'Main' server configuration

ServerAdmin root@localhost
#系统管理员的EMAIL,当网页出现问题时,错误信息会提示管理员联系EMIAL.

#ServerName www.example.com:80
#设定主机名称,这个值如果不设定,将会以hostname的输出为依据,填入的这个主机名称要能找到IP才行.

UseCanonicalName Off
#是否使用标准主机名称,如果你的主机有多个主机名称,若这个设定为on,那么apache只接受上面servername指定的主机名称而已,请使用off

DocumentRoot "/var/www/html"
#这个规范了WWW服务器主网页所旋转的目录,虽然这个值可以变动,但要注意相应目录的权限以及SELINUX的相关规则与类型才可以.

<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
#这个是针对www服务器的默认环境而来的.因为针对/的设定.

DirectoryIndex index.html index.html.var
#首页档案的设定.

<Directory "/var/www/html">
#针对特定目录的限制,
Options Indexes FollowSymLinks
#Indexes 如果在此目录下找不到首页档案时,就会显示整个目录下的档案名称.directoryindex设定首页文件.
#FollowSymLinks 让连接档可以生效.
#ExecCGI 让此目录具有执行CGI程式的权限.
#Includes 让一些server side inclued程式可以运行.
#MultiViews这个是多国语言的支抚持,与语系资料有关.在同一部主机中,可以依据用户端的语系而给不同的语言显示.

AllowOverride None
#AllowOverride表示是否允许额外设定档.htaccess的某些参数
#ALL:全部的權限均可被覆寫;
#AuthConfig:僅有網頁認證 (帳號密碼) 可覆寫;
#Indexes:僅允許 Indexes 方面的覆寫;
#Limits:允許使用者利用 Allow, Deny 與 Order 管理可瀏覽的權限;
#None:不可覆寫,亦即讓 .htaccess 檔案失效!

Order allow,deny
#能否登入浏览的参数.
#deny,allow 以deny优先处理,不符合规则的则为allow.
#allow,deny 以allow优先处理,不符合规则的为deny.
#order allow,deny 用于开放所有,拒绝特定.
#order deny,allow 用于拒绝所有,开放特定.
Allow from all
#允许所有的.配合上面的参数一起使用.
# Deny from 10.1.230.35
#拒绝某个IP
Deny from .midland.com.cn
#拒绝某个网域,如果要想禁止某个IP或网域访问最好使用IPTABLES ,如果只想对某个目录限制,可以使用order allow,deny.
</Directory>

#################.htaccess额外设定档与网页认证设置###############
AccessFileName .htaccess
<Files ~ "^\.ht">
Order allow,deny
Deny from all
</Files>
#下面是相关目录的设置,.htaccess的设定一定在存在上面的参数才行。
<Directory "/var/www/html/protect">
AllowOverride AuthConfig
#AllowOverride表示允许.htaccess额外设定档。
#AuthConfig 表示仅有网页认证的用户可读写。
Order allow,deny
#允许所有,拒绝特定
Allow from all
#允许所有。
</Directory>

#上面设定完成后,要建立.htaccess文件,这个文件是放在上面设定目录的下面。具体见附件.htaccess
#用命令htpasswd生成密码文件。相应指令如下:
#-c 建立后面的密码文件,如果此文件已经存在,则原本的资料会被删除,第一次建立时使用。
#-m 不使用默认的crvpt加密,改用md5加密。
#-d 使用更复杂的SHA方式来加密,
#-D 删除后面接的那个账号。

###########################END###############################

#<Directory /home/*/public_html>
# <Limit GET POST OPTIONS>
# Order allow,deny
# Allow from all
# </Limit>
# <LimitExcept GET POST OPTIONS>
# Order deny,allow
# Deny from all
# </LimitExcept>
#</Directory>
#透过limit与limitexcept能够处理用户端能够进行的动作。也就有办法针对资料进行编辑保护。不过,一般小网站用不到这个参数。

Alias /icons/ "/var/www/icons/"
<Directory "/var/www/icons">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
#虚拟目录的配置.

###########这里是虚拟主机的配置,最好的办法是将配置文件单独放在/etc/httpd/conf.d/下面。这样就不需要更改主配置文件。具体见附件virtual.conf##############
#NameVirtualHost *:80
#<VirtualHost *:80>
# ServerAdmin webmaster@dummy-host.example.com
# DocumentRoot /www/docs/dummy-host.example.com
# ServerName dummy-host.example.com
# ErrorLog logs/dummy-host.example.com-error_log
# CustomLog logs/dummy-host.example.com-access_log common
#</VirtualHost>
#######################END###################

<IfModule mod_userdir.c>
#UserDir disable
UserDir www
</IfModule>
#这个参数可以定义用户自己的网页.将上面的userdir disable用户目录禁止选项关掉,然后用userdir www来定义用户自己的网页位于用户主目录下的 www里面.然后要重启httpd服务.
#当新增用户时,系统会参考/etc/skel目录内的内容,可以mkdir /etc/skel/www新建一个www目录,这样,每当新增用户时,会自动生成www用户自己存放网页的目录,
#这里一定要注意目录及文件权限的问题,还有selinux的权限问题.可以使用chmod 755 setsebool -P httpd_enable_homedirs=1旅行个人首页规则, restorecon -Rv /home 处理安全类型.
#完成上面的设置后正常就可以通过http://localhost/~user/来浏览网页.可以通过ln -s /home/user/www user 来建立一个连接,之后就可以直接输http://localhost/user/来浏览了.而不用在输这个~符号.或者通过alias也可以实现.

AddHandler cgi-script .cgi .pl
#设置档名为cgi和pl的文件都可以执行.
<Directory "/var/www/html/cgi">
Options +ExecCGI
AllowOverride None
#是否允许.httpaccess额外设定文件.
Order allow,deny
Allow from all
</Directory>
#来设置开放某些目录的CGI执行权限.
#下面的方法也可以实现.
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
<Directory "/var/www/cgi-bin">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
#指定此目录下具有execcgi执行能力.也是虚拟目录.这种方法和上面的方法实现同样的功能.最好不需要两个同时用.

AddDefaultCharset UTF-8
#这个值是意思是说,让服务器传输强制使用utf-8编码的信息给用户端浏览器.因此不论网页内容为什么,反正在用户端浏览器都会使用utf-8编码来显示.如果网页使用的不是utf-8编码,此时就会出现乱码.所以这个值最好注解掉.修改后客户端也要清除cache才行的.

#####################下面是错误页面的自定义###############
#ErrorDocument 500 "The server made a boo boo."
ErrorDocument 404 /missing.html
#注,这里的missing.html文件一定要放在主目录下,也就是/var/www/html.和上面定义的DocumentRoot "/var/www/html"一样.
#还有,这个文件一定要大于512字节,否则不会显示.**********
#ErrorDocument 404 "/cgi-bin/missing_handler.pl"
#ErrorDocument 402 http://www.example.com/subscription_info.html #
# Alias /error/include/ "/your/include/path/"
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>
# ErrorDocument 400 /error/HTTP_BAD_REQUEST.html.var
# ErrorDocument 401 /error/HTTP_UNAUTHORIZED.html.var
# ErrorDocument 403 /error/HTTP_FORBIDDEN.html.var
# ErrorDocument 404 /error/HTTP_NOT_FOUND.html.var
# ErrorDocument 405 /error/HTTP_METHOD_NOT_ALLOWED.html.var
# ErrorDocument 408 /error/HTTP_REQUEST_TIME_OUT.html.var
# ErrorDocument 410 /error/HTTP_GONE.html.var
# ErrorDocument 411 /error/HTTP_LENGTH_REQUIRED.html.var
# ErrorDocument 412 /error/HTTP_PRECONDITION_FAILED.html.var
# ErrorDocument 413 /error/HTTP_REQUEST_ENTITY_TOO_LARGE.html.var
# ErrorDocument 414 /error/HTTP_REQUEST_URI_TOO_LARGE.html.var
# ErrorDocument 415 /error/HTTP_UNSUPPORTED_MEDIA_TYPE.html.var
# ErrorDocument 500 /error/HTTP_INTERNAL_SERVER_ERROR.html.var
# ErrorDocument 501 /error/HTTP_NOT_IMPLEMENTED.html.var
# ErrorDocument 502 /error/HTTP_BAD_GATEWAY.html.var
# ErrorDocument 503 /error/HTTP_SERVICE_UNAVAILABLE.html.var
# ErrorDocument 506 /error/HTTP_VARIANT_ALSO_VARIES.html.var
</IfModule>
</IfModule>
#######################错误页面自定义############################

#

TypesConfig /etc/mime.types

DefaultType text/plain

<IfModule mod_mime_magic.c>
# MIMEMagicFile /usr/share/magic.mime
MIMEMagicFile conf/magic
</IfModule>

HostnameLookups Off

#EnableMMAP off

#EnableSendfile off

ErrorLog logs/error_log

LogLevel warn

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

#LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio

#CustomLog logs/access_log common

#CustomLog logs/referer_log referer
#CustomLog logs/agent_log agent

CustomLog logs/access_log combined

ServerSignature On

<IfModule mod_dav_fs.c>
# Location of the WebDAV lock database.
DAVLockDB /var/lib/dav/lockdb
</IfModule>

IndexOptions FancyIndexing VersionSort NameWidth=* HTMLTable

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

AddIconByType (TXT,/icons/text.gif) text/*
AddIconByType (IMG,/icons/image2.gif) image/*
AddIconByType (SND,/icons/sound2.gif) audio/*
AddIconByType (VID,/icons/movie.gif) video/*

AddIcon /icons/binary.gif .bin .exe
AddIcon /icons/binhex.gif .hqx
AddIcon /icons/tar.gif .tar
AddIcon /icons/world2.gif .wrl .wrl.gz .vrml .vrm .iv
AddIcon /icons/compressed.gif .Z .z .tgz .gz .zip
AddIcon /icons/a.gif .ps .ai .eps
AddIcon /icons/layout.gif .html .shtml .htm .pdf
AddIcon /icons/text.gif .txt
AddIcon /icons/c.gif .c
AddIcon /icons/p.gif .pl .py
AddIcon /icons/f.gif .for
AddIcon /icons/dvi.gif .dvi
AddIcon /icons/uuencoded.gif .uu
AddIcon /icons/script.gif .conf .sh .shar .csh .ksh .tcl
AddIcon /icons/tex.gif .tex
AddIcon /icons/bomb.gif core

AddIcon /icons/back.gif ..
AddIcon /icons/hand.right.gif README
AddIcon /icons/folder.gif ^^DIRECTORY^^
AddIcon /icons/blank.gif ^^BLANKICON^^

DefaultIcon /icons/unknown.gif

#AddDescription "GZIP compressed document" .gz
#AddDescription "tar archive" .tar
#AddDescription "GZIP compressed tar archive" .tgz

ReadmeName README.html
HeaderName HEADER.html

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

# DefaultLanguage nl
AddLanguage ca .ca
AddLanguage cs .cz .cs
AddLanguage da .dk
AddLanguage de .de
AddLanguage el .el
AddLanguage en .en
AddLanguage eo .eo
AddLanguage es .es
AddLanguage et .et
AddLanguage fr .fr
AddLanguage he .he
AddLanguage hr .hr
AddLanguage it .it
AddLanguage ja .ja
AddLanguage ko .ko
AddLanguage ltz .ltz
AddLanguage nl .nl
AddLanguage nn .nn
AddLanguage no .no
AddLanguage pl .po
AddLanguage pt .pt
AddLanguage pt-BR .pt-br
AddLanguage ru .ru
AddLanguage sv .sv
AddLanguage zh-CN .zh-cn
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

ForceLanguagePriority Prefer Fallback

#AddType application/x-tar .tgz

#AddEncoding x-compress .Z
#AddEncoding x-gzip .gz .tgz

AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz

AddHandler cgi-script .cgi
#AddHandler send-as-is asis
AddHandler type-map var
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml

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

BrowserMatch "Microsoft Data Access Internet Publishing Provider" redirect-carefully
BrowserMatch "MS FrontPage" redirect-carefully
BrowserMatch "^WebDrive" redirect-carefully
BrowserMatch "^WebDAVFS/1.[0123]" redirect-carefully
BrowserMatch "^gnome-vfs/1.0" redirect-carefully
BrowserMatch "^XML Spy" redirect-carefully
BrowserMatch "^Dreamweaver-WebDAV-SCM1" redirect-carefully

#<Location /server-info>
# SetHandler server-info
# Order deny,allow
# Deny from all
# Allow from .example.com
#</Location>

#<IfModule mod_proxy.c>
#ProxyRequests On
#
#<Proxy *>
# Order deny,allow
# Deny from all
# Allow from .example.com
#</Proxy>

#
#ProxyVia On

#
#
#<IfModule mod_disk_cache.c>
# CacheEnable disk /
# CacheRoot "/var/cache/mod_proxy"
#</IfModule>
#

#</IfModule>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息